Example #1
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:
            client.register_webhook(config['env_name'], callback_url)
            client.subscribe_to_webhook(config['env_name'])
        except Exception as e:  # pragma: no cover
            logger.exception(six.text_type(e))
Example #2
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:
            client.register_webhook(config["env_name"], callback_url)
            client.subscribe_to_webhook(config["env_name"])
        except Exception as e:  # pragma: no cover
            logger.exception(str(e))
Example #3
0
    def activate(self, channel):
        config = channel.config_json()
        client = TembaTwython(config['api_key'], config['api_secret'], config['access_token'], config['access_token_secret'])

        callback_url = 'https://%s%s' % (settings.HOSTNAME, reverse('courier.twt', args=[channel.uuid]))
        webhook = client.register_webhook(callback_url)
        client.subscribe_to_webhook(webhook['id'])

        # save this webhook for later so we can delete it
        config['webhook_id'] = webhook['id']
        channel.config = json.dumps(config)
        channel.save(update_fields=('config',))
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)