Before you can get started, you need to do the following:
Set all Conversation API configuration settings.
- Python and a familiarity with how to create a new file.
Using the Conversation API, you can send messages to any channel you have configured. This tutorial shows you how to set up and send a message in a Python application.
This tutorial uses basic authentication for testing purposes. We recommend OAuth 2.0 authentication in a production environment. Read more about authentication methods.
Create a new file named
send-message.pyand paste the provided "send-message.py" code found on this page into the file. This code sends a text message.send-message.py# Find your App ID at dashboard.sinch.com/convapi/apps # Find your Project ID at dashboard.sinch.com/settings/project-management # Get your Access Key and Access Secret at dashboard.sinch.com/settings/access-keys import requests import base64 appId = "" accessKey = "" accessSecret = "" projectId = "" channel = "" identity = "" url = "https://us.conversation.api.sinch.com/v1/projects/" + projectId + "/messages:send" data = accessKey + ":" + accessSecret encodedBytes = base64.b64encode(data.encode("utf-8")) accessToken = str(encodedBytes, "utf-8") payload = { "app_id": appId, "recipient": { "identified_by": { "channel_identities": [ { "channel": channel, "identity": identity } ] } }, "message": { "text_message": { "text": "Text message from Sinch Conversation API." } } } headers = { "Content-Type": "application/json", "Authorization": "Basic " + accessToken } response = requests.post(url, json=payload, headers=headers) data = response.json() print(data)Note:This sample code is configured for the US region. If your Conversation API app wasn't created in the US region, replace all instances of
https://us.conversation.api.sinch.comwithhttps://eu.conversation.api.sinch.comin the sample code.Assign your values to the following parameters:
Parameter Your value appIdFind your app ID on your Sinch [dashboard](https://dashboard.sinch.com/convapi/apps). accessKeyFind your access key on your Sinch [dashboard](https://dashboard.sinch.com/settings/access-keys). accessSecretFind your access secret on your Sinch [dashboard](https://dashboard.sinch.com/settings/access-keys).
Note:Access secrets are only available during initial key creation.projectIdFind your project ID on your Sinch [dashboard](https://dashboard.sinch.com/settings/project-management). channelThe channel you want to use to send the message. Available channels are configured for the app on your Sinch [dashboard](https://dashboard.sinch.com/settings/access-keys). This guide assumes you've started with an SMSchannel, but you can use any channel configured for your app:SMSMESSENGERMMSRCSWHATSAPPVIBERVIBERBMINSTAGRAMTELEGRAMKAKAOTALKAPPLEBCLINEWECHAT
identityThe ID of the contact to which you want to send the message. Save the file.
Now you can execute the code and send your test message. Open a command prompt or terminal to the location where your Python file is saved and run the following command:
python send-message.pyYou should receive a message in your configured messaging platform.
Now that you know how to send a message, next learn how to handle an incoming message.
Read the links below to learn more: