def send_message(self, from_number, to_number, text): from temba.channels.models import SendException params = dict(api_key=self.api_key, api_secret=self.api_secret) params['from'] = from_number.strip('+') params['to'] = to_number.strip('+') params['text'] = text params['status-report-req'] = 1 # if this isn't going to work as plaintext, send as unicode instead if not is_gsm7(text): params['type'] = 'unicode' response = requests.get(NexmoClient.SEND_URL, params=params) response_json = response.json() messages = response_json.get('messages', []) if not messages or int(messages[0]['status']) != 0: raise SendException( u"Failed sending message, received error status [%s]" % messages[0]['status'], method=response.request.method, url=response.request.url, request=None, response=response.text, response_status=response.status_code) else: return (messages[0]['message-id'], response)
def send_message_via_nexmo(self, from_number, to_number, text): from temba.channels.models import SendException params = dict(api_key=self.api_key, api_secret=self.api_secret) params['from'] = from_number.strip('+') params['to'] = to_number.strip('+') params['text'] = text params['status-report-req'] = 1 # if this isn't going to work as plaintext, send as unicode instead if not is_gsm7(text): params['type'] = 'unicode' log_params = params.copy() log_params['api_secret'] = 'x' * len(log_params['api_secret']) log_url = NexmoClient.SEND_URL + '?' + urlencode(log_params) event = HttpEvent('GET', log_url) try: response = requests.get(NexmoClient.SEND_URL, params=params) event.status_code = response.status_code event.response_body = response.text response_json = response.json() messages = response_json.get('messages', []) except Exception: raise SendException(u"Failed sending message: %s" % response.text, event=event) if not messages or int(messages[0]['status']) != 0: raise SendException(u"Failed sending message, received error status [%s]" % messages[0]['status'], event=event) else: return messages[0]['message-id'], event
def send_message(self, from_number, to_number, text): from temba.channels.models import SendException params = dict(api_key=self.api_key, api_secret=self.api_secret) params['from'] = from_number.strip('+') params['to'] = to_number.strip('+') params['text'] = text params['status-report-req'] = 1 # if this isn't going to work as plaintext, send as unicode instead if not is_gsm7(text): params['type'] = 'unicode' response = requests.get(NexmoClient.SEND_URL, params=params) response_json = response.json() messages = response_json.get('messages', []) if not messages or int(messages[0]['status']) != 0: raise SendException(u"Failed sending message, received error status [%s]" % messages[0]['status'], method=response.request.method, url=response.request.url, request=None, response=response.text, response_status=response.status_code) else: return (messages[0]['message-id'], response)
def send_message(self, from_number, to_number, text): from temba.channels.models import SendException params = dict(api_key=self.api_key, api_secret=self.api_secret) params["from"] = from_number.strip("+") params["to"] = to_number.strip("+") params["text"] = text params["status-report-req"] = 1 # if this isn't going to work as plaintext, send as unicode instead if not is_gsm7(text): params["type"] = "unicode" log_params = params.copy() log_params["api_secret"] = "x" * len(log_params["api_secret"]) log_url = NexmoClient.SEND_URL + "?" + urlencode(log_params) try: response = requests.get(NexmoClient.SEND_URL, params=params) response_json = response.json() messages = response_json.get("messages", []) except: raise SendException( "Failed sending message: %s" % response.text, method=response.request.method, url=log_url, request=None, response=response.text, response_status=response.status_code, ) if not messages or int(messages[0]["status"]) != 0: raise SendException( "Failed sending message, received error status [%s]" % messages[0]["status"], method=response.request.method, url=log_url, request=None, response=response.text, response_status=response.status_code, ) else: return messages[0]["message-id"], response