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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file bird_python-0.1.2.tar.gz.

File metadata

  • Download URL: bird_python-0.1.2.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.10

File hashes

Hashes for bird_python-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9d801e9908cf5d363ea7e47ab4f3489673a6aad1936e6dc4009e5401e03fac98
MD5 f7f2774bf4545ffa3978ae4785b68cab
BLAKE2b-256 f9e7415bbf67fe72d8641abb8e8c7b0243839a2981148d9c83cd2810bcdb90f3

See more details on using hashes here.

File details

Details for the file bird_python-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: bird_python-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.8.10

File hashes

Hashes for bird_python-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e3ab6a09329c1bb6852b3089925268d4b7b0884924b3fb6ebc4197f902ef1f84
MD5 05070928f2c124be265d82e0018846fd
BLAKE2b-256 de12f6aac9953a6949e5095095a0a868b6c60b9135ad2329d275f1956b9077f1

See more details on using hashes here.

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