public async Task Unsubscribe(WebSubHandler webSubHandler)
        {
            if (externalURL is null || subURL is null)
            {
                return;
            }

            TaskCompletionSource taskCompletionSource = new TaskCompletionSource();

            webSubHandler.NotifyPendingClosure("/TASagentBotAPI/WebSub/Followers", taskCompletionSource);

            //Try unsubscribing
            await helixHelper.WebhookSubscribe(
                callback : externalURL,
                mode : "unsubscribe",
                topic : subURL,
                lease : 0,
                secret : "");

            //Clear values
            externalURL = null;
            subURL      = null;

            await taskCompletionSource.Task;
        }
Beispiel #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;
            }
        }