diff --git a/README.md b/README.md index 5adac28..2c76ec2 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/messagebird/__init__.py b/messagebird/__init__.py index a25b3e7..10d9c79 100644 --- a/messagebird/__init__.py +++ b/messagebird/__init__.py @@ -1,2 +1,2 @@ -from messagebird.client import Client, ErrorException +from messagebird.client import Client, ErrorException, Feature from messagebird.signed_request import SignedRequest diff --git a/messagebird/client.py b/messagebird/client.py index 671b2f3..143591f 100644 --- a/messagebird/client.py +++ b/messagebird/client.py @@ -1,6 +1,7 @@ import sys import json import io +import enum from messagebird.balance import Balance from messagebird.call import Call @@ -19,6 +20,7 @@ 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]) @@ -26,6 +28,10 @@ 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' @@ -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."""