def process_incoming_message(*args, **kwargs): try: from corehq.apps.telerivet.views import TELERIVET_INBOUND_FIELD_MAP fields = {a: kwargs[a] for (a, b) in TELERIVET_INBOUND_FIELD_MAP} log = IncomingRequest(**fields) log.save() except Exception as e: notify_exception(None, "Could not save Telerivet log entry") pass backend = TelerivetBackend.by_webhook_secret(kwargs["secret"]) if backend is None: # Ignore the message if the webhook secret is not recognized return if kwargs["from_number_e164"]: from_number = strip_plus(kwargs["from_number_e164"]) else: from_number = strip_plus(kwargs["from_number"]) if kwargs["event"] == EVENT_INCOMING: if kwargs["message_type"] == MESSAGE_TYPE_SMS: incoming_sms(from_number, kwargs["content"], TelerivetBackend.get_api_id()) elif kwargs["message_type"] == MESSAGE_TYPE_CALL: incoming_ivr(from_number, None, "TELERIVET-%s" % kwargs["message_id"], None)
def clean_webhook_secret(self): # Circular import from corehq.apps.telerivet.models import TelerivetBackend value = self.cleaned_data.get("webhook_secret", None) backend = TelerivetBackend.by_webhook_secret(value) if backend is not None and backend._id != self._cchq_backend_id: raise ValidationError(_("Already in use.")) return value
def process_incoming_message(*args, **kwargs): backend = TelerivetBackend.by_webhook_secret(kwargs["secret"]) if backend is None: # Ignore the message if the webhook secret is not recognized return if kwargs["event"] == EVENT_INCOMING: if kwargs["message_type"] == MESSAGE_TYPE_SMS: incoming_sms(kwargs["from_number"], kwargs["content"], TelerivetBackend.get_api_id())
def process_incoming_message(*args, **kwargs): backend = TelerivetBackend.by_webhook_secret(kwargs["secret"]) if backend is None: # Ignore the message if the webhook secret is not recognized return from_number = strip_plus(kwargs["from_number"]) if backend.country_code: if not from_number.startswith(backend.country_code): from_number = "%s%s" % (backend.country_code, from_number) if kwargs["event"] == EVENT_INCOMING: if kwargs["message_type"] == MESSAGE_TYPE_SMS: incoming_sms(from_number, kwargs["content"], TelerivetBackend.get_api_id()) elif kwargs["message_type"] == MESSAGE_TYPE_CALL: incoming_ivr(from_number, None, "TELERIVET-%s" % kwargs["message_id"], None)
def incoming_message(request): event = request.POST.get("event") message_id = request.POST.get("id") message_type = request.POST.get("message_type") from_number = request.POST.get("from_number") contact_id = request.POST.get("contact_id") phone_id = request.POST.get("phone_id") to_number = request.POST.get("to_number") time_created = request.POST.get("time_created") time_sent = request.POST.get("time_sent") content = request.POST.get("content") project_id = request.POST.get("project_id") secret = request.POST.get("secret") backend = TelerivetBackend.by_webhook_secret(secret) if backend is None: return HttpResponse(status=404) if event == EVENT_INCOMING: if message_type == MESSAGE_TYPE_SMS: incoming_sms(from_number, content, TelerivetBackend.get_api_id()) return HttpResponse()