
Once a user starts a “session” by sending you a message, you can exchange free-form messages with them for 24 hours. Template messages are the initial messages you send to users, and must follow a pre-approved template cleared by WhatsApp. WhatsApp divides outgoing messages into two categories: template messages and session messages. This is because WhatsApp only allows sending media on session messages. This means media files are not allowed in pre-approved templates. If a user has not sent a message to your WhatsApp number within the past 24 hours, you cannot send them a media message through WhatsApp. You can send media messages to any WhatsApp user who has sent you a message within the past 24 hours.
Line 6 update with your Account SID and Auth Token.įor full details, including sample code from our Helper Library SDKs, please see Twilio API for WhatsApp (Twilio Docs). Line 5 update with a valid media file url. For more information, see the Rules and Limitations section below. Unprompted messages have template requirements. Note: A free-form message like this is only possible during a 24 hour user-initiated session. Line 4 update with your desired message. Unless your Twilio number has been enabled for WhatsApp in production, use your WhatsApp Sandbox number for sending messages. Line 3 update with a valid WhatsApp sender number. Line 2 update with a valid destination. To make this script work for you, make the following updates, and then paste it into a terminal window: This example will contact the WhatsApp destination (310) 555-5555 from the sender (212) 555-1234 via the WhatsApp app, and includes the image owl.png, and the following message: Thanks for contacting me on WhatsApp! Here is a picture of an owl.
u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token' data-urlencode "Body=Thanks for contacting me on WhatsApp! Here is a picture of an owl." \ Here’s an example cURL script: curl -XPOST \ This is exactly like sending an MMS message with Twilio Programmable SMS. To send a media message with WhatsApp, include the MediaUrl parameter with your HTTP POST request.
File name behavior on WhatsApp media messages. Any additional attachments will be ignored. Please note that, unlike MMS, a WhatsApp media message can only contain one media attachment. The API works like sending MMS messages with Twilio, however there are some rules and restrictions that are unique to WhatsApp. The Twilio for WhatsApp API supports sending and receiving media messages with WhatsApp users.