Twilio API for WhatsApp Tutorials
The Twilio API for WhatsApp adds two-way WhatsApp messaging to your web application. Because it uses the same Twilio API you use for SMS, you can add WhatsApp capabilities to an existing app by changing just two lines of code.
These tutorials cover common WhatsApp use cases to get you started.
These tutorials and guides show you how to use WhatsApp to power common messaging use cases. They include code samples in six languages so you can build with the tools you already use.
- Get started with WhatsApp and onboard your first sender
- Send and receive media messages in WhatsApp
- Send WhatsApp Notification Messages with Templates
- Use WhatsApp Business Accounts with Twilio
- Using WhatsApp with Twilio Conversations
- Formatting, location, and other rich messaging features in WhatsApp messaging
Once you're set up, send a message using one of six web languages or cURL. For an even quicker way to send your first WhatsApp message, see the WhatsApp quickstarts.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createMessage() {11const message = await client.messages.create({12body: "Your appointment is coming up on July 21 at 3PM",13from: "whatsapp:+552120420682",14to: "whatsapp:+13233633791",15});1617console.log(message.body);18}1920createMessage();
Response
1{2"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"api_version": "2010-04-01",4"body": "Your appointment is coming up on July 21 at 3PM",5"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",6"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",7"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",8"direction": "outbound-api",9"error_code": null,10"error_message": null,11"from": "whatsapp:+552120420682",12"num_media": "0",13"num_segments": "1",14"price": null,15"price_unit": null,16"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",17"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",18"status": "queued",19"subresource_uris": {20"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"21},22"to": "whatsapp:+13233633791",23"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"24}