Reply to Messages

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

Step 1: Handle inbound replies

Did you complete the Programmable Conversations Quickstart: Handle Inbound Messages?

  • No! It's a prerequisite, so make sure to do so before continuing.
  • Yes! Great, go to step 2.

Step 2: Run the code

Now you’re set up, you can 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.

To get a list of active conversations with their IDs, follow the explanation in the Programmatically handle inbound messages Quickstart.

$ 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.

Congrats! You can now programmatically reply to inbound messages with Programmable Conversations.

Next Steps

You may now want to check out these resources:

Questions?

We’re always happy to help with code or other questions you might have! Search our API Reference, check the Developer tutorials or contact support.

Cookie Settings