Example #1
0
    def deactivate(self, channel):
        config = channel.config_json()
        client = TembaTwython(config['api_key'], config['api_secret'],
                              config['access_token'],
                              config['access_token_secret'])

        client.delete_webhook(config['webhook_id'])
Example #2
0
 def deactivate(self, channel):
     config = channel.config
     if "webhook_id" in config:
         client = TembaTwython(config["api_key"], config["api_secret"],
                               config["access_token"],
                               config["access_token_secret"])
         client.delete_webhook(config["env_name"], config["webhook_id"])
Example #3
0
 def deactivate(self, channel):
     config = channel.config
     if "webhook_id" in config:
         client = TembaTwython(
             config["api_key"], config["api_secret"], config["access_token"], config["access_token_secret"]
         )
         client.delete_webhook(config["env_name"], config["webhook_id"])
Example #4
0
    def activate(self, channel):
        config = channel.config
        client = TembaTwython(
            config["api_key"], config["api_secret"], config["access_token"], config["access_token_secret"]
        )

        callback_url = "https://%s%s" % (channel.callback_domain, reverse("courier.twt", args=[channel.uuid]))
        try:
            # check for existing hooks, if there is just one, remove it
            hooks = client.get_webhooks(config["env_name"])
            if len(hooks) == 1:
                client.delete_webhook(config["env_name"], hooks[0]["id"])

            resp = client.register_webhook(config["env_name"], callback_url)
            channel.config["webhook_id"] = resp["id"]
            channel.save(update_fields=["config"])
            client.subscribe_to_webhook(config["env_name"])
        except Exception as e:  # pragma: no cover
            logger.exception(str(e))
            raise ValidationError(e)
Example #5
0
    def activate(self, channel):
        config = channel.config
        client = TembaTwython(config["api_key"], config["api_secret"],
                              config["access_token"],
                              config["access_token_secret"])

        callback_url = "https://%s%s" % (channel.callback_domain,
                                         reverse("courier.twt",
                                                 args=[channel.uuid]))
        try:
            # check for existing hooks, if there is just one, remove it
            hooks = client.get_webhooks(config["env_name"])
            if len(hooks) == 1:
                client.delete_webhook(config["env_name"], hooks[0]["id"])

            resp = client.register_webhook(config["env_name"], callback_url)
            channel.config["webhook_id"] = resp["id"]
            channel.save(update_fields=["config"])
            client.subscribe_to_webhook(config["env_name"])
        except Exception as e:  # pragma: no cover
            logger.exception(str(e))
            raise ValidationError(e)