API wrapper for MessageBird written in Python
Project description
Bird's REST API for Python
This repository contains the open source Python client for New MessageBird's REST API. Documentation can be found at: https://docs.bird.com/api/.
Requirements
- Sign up for a free MessageBird account
- Create a new access key in the developers sections
- An application written in Python (tested with Python 2.7 and Python 3.4)
Installation
The easiest way to install the bird_python package is either via pip:
$ pip install bird_python
Examples
We have put some self-explanatory examples in the examples directory, but here is a quick example on how to get started. Assuming the installation was successful, you can import the messagebird package like this:
import bird_python as messagebird
Then, create an instance of messagebird.Client:
client = messagebird.Client('YOUR_ACCESS_KEY', 'YOUR_ORGANIZATION_ID')
Now you can query the API for information or send a request. For example, if we want to send a message through any channel like whatsapp, you'd do something like this:
try:
# Get and set any workspace for sent request to the channels related.
client.workspaces = client.workspace_list()['results'][0]['id']
# Get and set any channel id for sender request, for example: Whatsapp, Messenger, SMS
channels_id = client.channel_list()['results'][0]['id']
# Build the body message like this format
body = {
"receiver": {
"contacts": [
{
"identifierValue": "+15598585"
}
]
},
"body": {
"type": "text",
"text": {
"text": "Single text message"
}
}
}
response = client.send_message(channels_id=channels_id, body=body)
# Print the object information.
print('response:\n')
print(response)
except messagebird.client.ErrorException as e:
print('Error:\n')
for error in e.errors:
print(' code : %d' % error.code)
print(' description : %s' % error.description)
print(' parameter : %s\n' % error.parameter)
Actions
- Get Contact
contact = client.contact(uuid='YOUR_CONTACT_ID')
# Retrieve the information of a specific contact.
- Create Contact
body = {
"displayName": "Jhon Doe",
"identifiers": [
{
"key": "phone",
"value": "+15551234"
}
]
}
contact = client.contact_create(body=body)
# Allows create a contact.
- Get Contact List
contact = client.contact_list()
# Extract all contacts created in a workspace.
- Get Workspace List
contact = client.workspace_list()
# Gets a list of workspaces created in an organization's account.
- Get Workspace By ID
contact = client.workspace_list_by_id(uuid='YOUR_WORKSPACE_ID')
# Gets a list of workspaces created in an organization's account.
- Get Project List
contact = client.project_list()
# Gets a list of projects created in an workspace.
# In this API you get what were previously known as templates,
# only now they can be compatible with multiple channels.
- Get Project By ID
contact = client.project_list_by_id(uuid='YOUR_PROJECT_ID')
# Gets one project created in an workspace by id.
- Get Channel List
contact = client.channel_list()
# Gets a list of channels created in an workspace.
- Get Channel By ID
contact = client.channel_list_by_id(uuid='YOUR_CHANNEL_ID')
# Gets one channel created in an workspace by id.
- Get Connector List
contact = client.connector_list()
# Gets a list of connectors created in an workspace.
# A connector can be Whatsapp, Messenger, SMS
- Get Connector By ID
contact = client.connector_list_by_id(uuid='YOUR_CONNECTOR_ID')
# Gets one connector created in an workspace by id.
- Send Message
body = {
"receiver": {
"contacts": [
{
"identifierValue": "+15551234"
}
]
},
"body": {
"type": "text",
"text": {
"text": "Single text message"
}
}
}
contact = client.send_message(channels_id='YOUR_CHANNEL_ID', body=body)
# Allows you to send a message through a channel.
# :param channels_id: ID of the channel through which you want to send the message
# :param body: Body of the message in json, which contains all the information necessary to send the message
- Get Webhook Event List
contact = client.webhook_event_list()
# Gets a list of webhooks available in an workspace.
- Create Webhook
contact = client.webhook_create(body='body')
# Allows create a webhook based in a event of available webhook list.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for bird_python-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3ab6a09329c1bb6852b3089925268d4b7b0884924b3fb6ebc4197f902ef1f84 |
|
MD5 | 05070928f2c124be265d82e0018846fd |
|
BLAKE2b-256 | de12f6aac9953a6949e5095095a0a868b6c60b9135ad2329d275f1956b9077f1 |