public async Task Subscribe()
        {
            //First, detect and unsubsribe from lingering webhooks
            TokenRequest tokenContainer = await helixHelper.GetClientCredentialsToken();

            TwitchWebhookResponse subscriptions = await helixHelper.GetWebhookSubscriptions(tokenContainer.AccessToken);

            if (subscriptions.Data is not null && subscriptions.Data.Count > 0)
            {
                communication.SendWarningMessage($"Unsubscribing from {subscriptions.Data.Count} existing webhooks");

                foreach (TwitchWebhookResponse.Datum datum in subscriptions.Data)
                {
                    bool success = await helixHelper.WebhookSubscribe(
                        callback : datum.Callback,
                        mode : "unsubscribe",
                        topic : datum.Topic,
                        lease : 0,
                        secret : "");

                    if (!success)
                    {
                        communication.SendWarningMessage($"Failed to unsub {datum.Callback} from: {datum.Topic}");
                    }
                }
            }


            foreach (IWebSubSubscriber subscriber in webSubSubscribers)
            {
                await subscriber.Subscribe(this);
            }
        }
Example #2
0
        public async Task Subscribe(WebSubHandler webSubHandler)
        {
            string externalAddress = await webAccessConfig.GetExternalWebSubAddress();

            externalURL = $"{externalAddress}/TASagentBotAPI/WebSub/Stream";
            subURL      = $"https://api.twitch.tv/helix/streams?user_id={botConfig.BroadcasterId}";

            bool success = await helixHelper.WebhookSubscribe(
                callback : externalURL,
                mode : "subscribe",
                topic : subURL,
                lease : 48 * 60 * 60,
                secret : webSubHandler.CreateSecretForRoute("/TASagentBotAPI/WebSub/Stream"));

            if (!success)
            {
                communication.SendErrorMessage("Failed to subscribe to Stream Changes. Aborting.");

                externalURL = null;
                subURL      = null;

                return;
            }

            TwitchStreams streamData = await helixHelper.GetStreams(userIDs : new List <string>()
            {
                botConfig.BroadcasterId
            });

            if (streamData.Data is null || streamData.Data.Count == 0)
            {
                currentStreamData = null;
            }
        public async Task Subscribe(WebSubHandler webSubHandler)
        {
            string externalAddress = await webAccessConfig.GetExternalWebSubAddress();

            externalURL = $"{externalAddress}/TASagentBotAPI/WebSub/Followers";

            subURL = $"https://api.twitch.tv/helix/users/follows?first=1&to_id={botConfig.BroadcasterId}";

            bool success = await helixHelper.WebhookSubscribe(
                callback : externalURL,
                mode : "subscribe",
                topic : subURL,
                lease : 48 * 60 * 60,
                secret : webSubHandler.CreateSecretForRoute("/TASagentBotAPI/WebSub/Followers"));

            if (!success)
            {
                communication.SendErrorMessage("Failed to subscribe to Follows. Aborting.");

                externalURL = null;
                subURL      = null;
            }
        }