HTTP API Request

:raised_hands: Hey guys i have a question :slight_smile: i work onmy MultiStream Extension and i was thinking it would be good if people can @Name in there title even if the person is not live.

Currently it takes everyone in the title and put it in a list and post it as a multilink :slight_smile:

someone suggest i should try it with DecAPI Docs but i never did a http request before in C#

would be nice if someone could help me out :smiley: (maybe splitting this into 2 part would be good ? ) 1 script for checking title and checking if he/she is live and another script for putting all toughter ? :smiley:

using System;
using System.Collections.Generic;
using System.Linq;

public class CPHInline
{
    public bool Execute()
    {
    
        //Get Broadcaster Infos
        string title = args["targetChannelTitle"].ToString(); CPH.LogVerbose("GET TITLE");  
        string broadcaster = args["targetUser"].ToString();  CPH.LogVerbose("GET BROADCASTER");  

        //Get Input (for command) example: !multistream
        string input= args.ContainsKey("rawInput") ? args["rawInput"].ToString() : "notimedaction";  CPH.LogVerbose("GET INPUT");  
        string messageMulti = args["messageMulti"].ToString(); CPH.LogVerbose("GET MULTIMESSAGE");  
        string messageNoMulti = args["messageNoMulti"].ToString(); CPH.LogVerbose("GET NOMULTI");  
        
        //Get Action Settings
        string streamService = args["streamService"].ToString(); CPH.LogVerbose("GET STREAMSERVICE");  
        
        //Set all lists
        List<string> formattedStreamers = new List<string>(); CPH.LogVerbose("GET FORMATTEDSTREAMERS LIST" );  
        List<string> streamers = new List<string>(); CPH.LogVerbose("GET STREAMERS LIST");  
        // Parse Stream Title

        string formattedStreamer = ""; CPH.LogVerbose("GET FORMATTEDSTREAMER STRING");  

        string[] words = title.Split(' '); CPH.LogVerbose("GET WORDS");        

        foreach (string word in words) 
        { CPH.LogVerbose("SEPERATE WORDS");
            if (word.StartsWith("@"))
            {
                streamers.Add(word.Substring(1)); // remove the "@"
            }
        }
        

        
        // Set Streamers for Multilink
    if(streamers.Any()) 
        {    CPH.LogVerbose("REPLACE @");
            foreach (string streamer in streamers) 
            {
                formattedStreamer = streamer.Replace(" ", ""); // remove spaces from the name
                formattedStreamers.Add(formattedStreamer);
            }

            string streamerList = string.Join("/", formattedStreamers);
            CPH.SendMessage(messageMulti + " " + streamService + broadcaster + "/" + streamerList);
        
        } else{
            if(input == "") 
            {
                CPH.SendMessage(messageNoMulti);
              
            } else {
                CPH.LogVerbose("NO MULTI");
                }
        }
        return true;
    }
}

Honestly if you use Decapi you can just use the built in subaction that Streamer.bot uses. That API sends a string back and there’s no parsing needed. So you could call it with the subaction and then bring the argument it creates into the C# like normal and then through a Contains on that argument in the C# to do what you want.

If there was parsing needed I’d dive into that for you but there’s no reason to do all that if there’s no parsing needed.

when i understand it right:

  • Create a Action with a the api and "example: %name% as thee argument
  • Each time it takes the name from the title run the action to check
  • if stream = true add to list else no

? :smiley:

This is basically how I had it for Thanos Snap.
image

So I used the variable %broadcastUser% to replace the name with my name and when the api returns from that endpoint offline in the string in the variable %live% I created in the api subaction then it just stops. If it contains the normal uptime from that endpoint it just continues on.

oh thats not what i mean :smiley:

I want to check the people in my title who are also streaming :slight_smile:

as a example when i have staying: playing some Hunt with "@"Ryuzaziki, "@"MadMasterSZ

only the poeple should be added into the multilink stream if they are also live :smiley:

Exactly, I gave you an example was all. So how do you get those names that you add in the title? You would do the same thing to send the names to that api url. Then if contains “offline” don’t set it.

I mean if you want you could dive into an api call but how you go about all that depends on where you’re getting the information from. But being you are trying to get that information from multiple people it may be cleaner to do an internal api call in a for loop than using decapi.

yeah this was my first idea :smiley: but i cant understand how it works in C# ^^ in SB :smiley:

i will try both out ^^ thanks :heart:

If you decide what api you want to use for sure we can take a look at how to do it in C#. It’s not super difficult but usually just needs some deserialization from most API’s.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.