This article is part of the Twilio Conversations API series
Using the Twilio Conversations API, you can create cross channel communications applications across SMS, Chat, and WhatsApp.
The first fundamental step towards integrating with this API is by creating a Conversation. A Conversation can be thought of as a virtual container to house participants. It allows participants to exchange messages with each other regardless of whether they are using SMS, Chat, or WhatsApp.
Setup
First, let’s run npm init to create the package.json file. To quickly get started, you will use the -y flag for defaults.
npm init -y
Next, install Babel so that you’re using modern day ES6 syntax
npm i @babel/core @babel/node @babel/preset-env
To use Babel, add a .babelrc file to the root directory of this project and populate it with the following
{
"presets": ["@babel/preset-env"]
}
Next, install the Twilio SDK
npm i twilio
Creating a Conversation
Finally, here’s how you create a Conversation. You can get the Twilio Account SID and Twilio Auth Token from your Twilio Console.
const accountSid = INSERT_YOUR_TWILIO_ACCOUNT_SID;
const authToken = INSERT_YOUR_TWILIO_AUTH_TOKEN;
const client = require("twilio")(accountSid, authToken);
(async () => {
const conversation = await client.conversations.conversations.create({
friendlyName: "My first conversation",
});
console.log(conversation);
})();
If you navigate to the Conversations panel in your Twilio Console, you should see the Conversation you just created listed.
Interested in learning more about Twilio Conversations? Check out my upcoming eBook on Twilio Conversations and other articles.