Replying to messages

In this Programmable Conversations API Quickstart, you'll learn how to programmatically reply to inbound messages using cURL by adding a new message to an existing conversation and sending it to the contact with whom you're communicating.

Programmable Conversations allows you to reply to a user's message over any supported communication platform such as SMS, WhatsApp, Live Chat, WeChat, Messenger, Telegram, LINE, Instagram, Email, Google Business Messages, Twitter, and Viber.

Step 1: Handle inbound replies

Before we start, have you completed the Programmable Conversations Quickstart: Receiving Messages?

  • No? Make sure to do so before continuing with this quickstart.
  • Yes? Great! Go to step 2.

Step 2: Run the code

Run the following request in your terminal after replacing YOUR-API-KEY with your API key and CONVERSATION-ID with the ID of an existing conversation.

You can collect your live API key from the Developer Dashboard. To get a list of active conversations with their IDs, simply head over to the Receiving messages quickstart.

Once you entered all your credentials, go ahead and copy the above snippet to your terminal and hit enter!

curl -X "POST" "https://conversations.messagebird.com/v1/conversations/CONVERSATION-ID/messages" \
-H "Authorization: AccessKey YOUR-API-KEY" \
-H "Content-Type: application/json" \
--data '{"type": "text","content":{"text": "Hello, this is a reply!"}}'

Step 3: View the response

Have a look at MessageBird’s HTTP response to your API call. If everything was correct, you'll receive a response similar to this:

{
"id": "52ac5ef671d55bae0ad1532581a618c8",
"conversationId": "f1e812e9afd6a875d813d51f45823edd",
"channelId": "2ceefea7c1b8c79673215c42c1a6b916",
"status": "pending",
"type": "text",
"direction": "sent",
"content": {
"text": "Hello, this is a reply!"
},
"createdDatetime": "2018-08-29T13:53:44.642664784Z",
"updatedDatetime": "2018-08-29T13:53:44.673850825Z"
}

If something went wrong, you’ll receive an error response from the MessageBird API. Don't worry, simply head over to Conversations API Troubleshooting to understand the error.

Nice work! 🎉 You can now programmatically reply to inbound messages with Programmable Conversations.

Questions?

We’re always happy to help with code or other doubts you might have! Check out our Quickstarts, API Reference, Tutorials, SDKs, or contact our Support team.

Cookie Settings