Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ Your balance:

Please see the other examples for a complete overview of all the available API calls.

Conversations WhatsApp Sandbox
-------------
To use the whatsapp sandbox you need to add `messagebird.Feature.ENABLE_CONVERSATIONS_API_WHATSAPP_SANDBOX` to the list of features you want enabled. Don't forget to replace `YOUR_ACCESS_KEY` with your actual access key.

```python
client = messagebird.Client('1ekjMs368KTRlP0z6zfG9P70z', features=[messagebird.Feature.ENABLE_CONVERSATIONS_API_WHATSAPP_SANDBOX])
```

Documentation
-------------
Complete documentation, instructions, and examples are available at:
Expand Down
2 changes: 1 addition & 1 deletion messagebird/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from messagebird.client import Client, ErrorException
from messagebird.client import Client, ErrorException, Feature
from messagebird.signed_request import SignedRequest
21 changes: 16 additions & 5 deletions messagebird/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import json
import io
import enum

from messagebird.balance import Balance
from messagebird.call import Call
Expand All @@ -19,13 +20,18 @@
from messagebird.conversation_webhook import ConversationWebhook, ConversationWebhookList
from messagebird.voice_recording import VoiceRecordingsList, VoiceRecording


ENDPOINT = 'https://rest.messagebird.com'
CLIENT_VERSION = '1.4.1'
PYTHON_VERSION = '%d.%d.%d' % (sys.version_info[0], sys.version_info[1], sys.version_info[2])
USER_AGENT = 'MessageBird/ApiClient/%s Python/%s' % (CLIENT_VERSION, PYTHON_VERSION)
REST_TYPE = 'rest'

CONVERSATION_API_ROOT = 'https://conversations.messagebird.com/v1/'
CONVERSATION_API_WHATSAPP_SANDBOX_ROOT = 'https://whatsapp-sandbox.messagebird.com/v1/'



CONVERSATION_PATH = 'conversations'
CONVERSATION_MESSAGES_PATH = 'messages'
CONVERSATION_WEB_HOOKS_PATH = 'webhooks'
Expand All @@ -44,23 +50,28 @@ def __init__(self, errors):
message = ' '.join([str(e) for e in self.errors])
super(ErrorException, self).__init__(message)

class Feature(enum.Enum):
ENABLE_CONVERSATIONS_API_WHATSAPP_SANDBOX = 1

class Client(object):
def __init__(self, access_key, http_client=None):

def __init__(self, access_key, http_client=None, features=[]):
self.access_key = access_key
self.http_client = http_client

self.conversation_api_root = CONVERSATION_API_WHATSAPP_SANDBOX_ROOT if Feature.ENABLE_CONVERSATIONS_API_WHATSAPP_SANDBOX in features else CONVERSATION_API_ROOT

def _get_http_client(self, type=REST_TYPE):
if self.http_client:
return self.http_client

if type == REST_TYPE:
return HttpClient(ENDPOINT, self.access_key, USER_AGENT)

if type == CONVERSATION_TYPE:
return HttpClient(self.conversation_api_root, self.access_key, USER_AGENT)
if type == VOICE_TYPE:
return HttpClient(VOICE_API_ROOT, self.access_key, USER_AGENT)

return HttpClient(CONVERSATION_API_ROOT, self.access_key, USER_AGENT)
return HttpClient(ENDPOINT, self.access_key, USER_AGENT)

def request(self, path, method='GET', params=None, type=REST_TYPE):
"""Builds a request, gets a response and decodes it."""
Expand Down