e.iluf
e.iluf

Reputation: 1659

how to receive whatsapp message in twilio

i am trying to build an application that can recieve and respond to an sms or whatsapp message. i have been able to setup and connect the twilio number to WhatsApp API.

i was able to successful send a WhatsApp message with this function

def send_with_whatsapp():
    
    client = Client(account_sid, auth_token)

    message = client.messages.create(
                                body='Hello there!',
                                from_='whatsapp:+1xxxx',
                                to='whatsapp:+1xxxx'
                            )

    print(message.sid)




i am able to receive and respond sms with this function


@app.route("/sms", methods=['POST'])
def reply():
    
    incoming_msg = request.form.get('Body').lower()
    response = MessagingResponse()
    print(incoming_msg)

the problem is I could not figure out how to see the recieved WhatsApp messages. when a text is sent via regular sms, the recieved message is printed at print(incoming_msg) but when WhatsApp message is sent, nothing is printed. How can i print the recieved whatsapp messages in python?

Upvotes: 0

Views: 783

Answers (1)

tytang29
tytang29

Reputation: 1

incoming_message = request.POST.get('Body')
incoming_message = incoming_message.lower()
print(incoming_message)

See if this works for you.

Upvotes: 0

Related Questions