Sending Multiple SMS Messages in Twilio Reply
Question: I am writing software using the Twilio API, Flask, and Python to send and
receive SMS messages. When I reply to a message, I also want to send out a
message to a different phone number (thereby sending 2 messages in total, one
to the original sender, and one to an entirely different individual).

I reply to an SMS using:

    
    
    @app.route("/", methods=['GET', 'POST'])
    def reply():
    
        # Send other text
        sendMessage(to_number, text)
    
        # Send response      
        resp = twilio.twiml.Response()
        resp.sms(response)
        return str(resp)
    

Where the `sendMessage` function is:

    
    
    from twilio.rest import TwilioRestClient 
    
    def sendMessage(to_number, text): 
    
        ACCOUNT_SID = "XXXXXXXXX" 
        AUTH_TOKEN = "XXXXXXXX" 
        twilioNumber = "XXXXXXXXX"
    
        client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN) 
    
        client.messages.create(
            to=to_number, 
            from_=twilioNumber, 
            body=text,  
        )
    

But the `sendMessage` function does not actually send a text to the separate
number (note the reply still works). Note also that the `sendMessage`function
works fine when it is called outside of the reply function.

How should I go about sending two different texts to two different numbers in
response to a text from only one of those numbers?


Answer: This worked for me to send the same message to multiple numbers:

    
    
    from twilio.rest import TwilioRestClient 
    
    def sendMessage(text):
        ACCOUNT_SID = "ACXXXXXXXX" 
        AUTH_TOKEN = "YYYYYYYYYY"
        twilioNumber = "+15551235554"
        client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
    
        NUMBERS = {
            'Foo':'+15551235555',
            'Bar':'+15551235556'
        }
    
        for name, number in NUMBERS.items():
            message = client.messages.create(
                to=number, 
                from_=twilioNumber, 
                body=text)
            print message.sid
    

Maybe you can find a way to adapt this to your specific needs. Note that
Twilio limits your outbound SMS to 1 SMS message segment per-second, per-
number. [More info on Rate-Limits](https://www.twilio.com/help/faq/twilio-
basics/what-are-the-limits-on-outbound-calls-and-sms-messages-per-second)

