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 app.
- PIP (package installer for Python) and a familiarity with how to install Python modules.
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.
The easiest way to install the SDK is using pip
:
- Open a command prompt or terminal to the local repository folder.
- Execute the following command:
pip install sinch
Now you can start setting up your 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.py
and paste the provided "send-message.py" code found on this page into the file. This code sends a text message.
from sinch import SinchClient
sinch_client = SinchClient(
key_id="YOUR_key_id",
key_secret="YOUR_key_secret",
project_id="YOUR_project_id"
)
# conversation_region must be set to either us or eu
sinch_client.configuration.conversation_region="us"
send_conversation_api_message_response = sinch_client.conversation.message.send(
app_id="YOUR_app_id",
recipient={
"identified_by" : {
"channel_identities" : [
{"identity":"RECIPIENT_number","channel" : "SMS"}
]
}
},
message={
"text_message" : {
"text" : "Text message from Sinch Conversation API."
}
},
channel_properties={
"SMS_SENDER" : "YOUR_sms_sender"
}
)
print(send_conversation_api_message_response)
This sample code is configured for the US region. If your Conversation API app wasn't created in the US region, update sinch_client.configuration.conversation_region
to eu
.
The code provided includes placeholder parameters. You'll need to update the parameters detailed in the following subsections with your values.
Before initializing a client using this SDK, you'll need three pieces of information:
- Your Project ID
- An access key ID
- An access key Secret
These values can be found on the <b>Access Keys</b> page of the Sinch Build Dashboard. You can also create new access key IDs and Secrets, if required.
If you have trouble accessing the above link, ensure that you have gained access to the Conversation API by accepting the corresponding terms and conditions.
Assign your values to the following parameters:
Placeholder value | Your value |
---|---|
YOUR_app_id | Find your app ID on your Sinch [dashboard](https://dashboard.sinch.com/convapi/apps). |
YOUR_channel | The channel you want to use to send the message. This guide presets this channel property to SMS , but you may update it to any channel that's already configured on your Conversation API app. You may add the following channels to your app from the [Sinch Build Dashboard](https://dashboard.sinch.com/settings/access-keys):
|
RECIPIENT_number | The channel identity of the recipient to which you want to send the message. When using the SMS channel, this will be a phone number. |
YOUR_sms_sender | Your Sinch virtual phone number, available on the [Sinch Build Dashboard](https://dashboard.sinch.com/numbers/your-numbers). This is only required if you are using the SMS channel. |
Ensure that you 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.py
You should receive a message in your configured messaging platform.
Read the links below to learn more: