Prerequisites:
- Python installed
- A text editor
Step 1: Set up a Project
Create an empty folder for your project, let’s name it testApp.
Step 2: Install the SDK
Run the code from the command line from the root of your project folder:
pip install messagemedia-messages-sdk
This command installs the package using which you can send messages.
Step 3: Add the Code
Create an index.js file inside the folder you created earlier and open it up in your editor. Write down the following code. .
from message_media_messages.message_media_messages_client import MessageMediaMessagesClient
import json
auth_user_name = 'YOUR_API_KEY'
auth_password = 'YOUR_API_SECRET'
use_hmac_authentication = False
client = MessageMediaMessagesClient(auth_user_name, auth_password, use_hmac_authentication)
messages_client = client.messages
body_value = '''{
"messages":[
{
"content":"My first message",
"destination_number":"+61491570156"
}
]
}'''
body = json.loads(body_value)
result = messages_client.send_messages(body)
Don’t forget to update the API credentials and the destination number.
Step 4: Save
Save your code and type the following in the console:
python index.py
A successful response should look like this:
Well done – that’s how simple it is to send a message using Python. Check out the API documentation and the Github repository to see what else you can do.
Comments
0 comments
Article is closed for comments.