Skip to main content

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

  1. Get Contact
contact = client.contact(uuid='YOUR_CONTACT_ID')
# Retrieve the information of a specific contact.
  1. Create Contact
body = {
        "displayName": "Jhon Doe",
        "identifiers": [
                {
                    "key": "phone",
                    "value": "+15551234"
                }
            ]
        }
contact = client.contact_create(body=body)
# Allows create a contact.
  1. Get Contact List
contact = client.contact_list()
# Extract all contacts created in a workspace.
  1. Get Workspace List
contact = client.workspace_list()
# Gets a list of workspaces created in an organization's account.
  1. 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.
  1. 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.
  1. Get Project By ID
contact = client.project_list_by_id(uuid='YOUR_PROJECT_ID')
# Gets one project created in an workspace by id.
  1. Get Channel List
contact = client.channel_list()
# Gets a list of channels created in an workspace.
  1. Get Channel By ID
contact = client.channel_list_by_id(uuid='YOUR_CHANNEL_ID')
# Gets one channel created in an workspace by id.
  1. Get Connector List
contact = client.connector_list()
# Gets a list of connectors created in an workspace.
# A connector can be Whatsapp, Messenger, SMS
  1. Get Connector By ID
contact = client.connector_list_by_id(uuid='YOUR_CONNECTOR_ID')
# Gets one connector created in an workspace by id.
  1. 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
  1. Get Webhook Event List
contact = client.webhook_event_list()
# Gets a list of webhooks available in an workspace.
  1. Create Webhook
contact = client.webhook_create(body='body')
# Allows create a webhook based in a event of available webhook list.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bird_python-0.1.2.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

bird_python-0.1.2-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page