Raised This Month: $ Target: $400
 0% 

[SNIPPET] SteamWorks to Slack (webhook)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
ImACow
AlliedModders Donor
Join Date: Feb 2015
Old 12-29-2016 , 15:35   [SNIPPET] SteamWorks to Slack (webhook)
Reply With Quote #1

Requires SteamWorks

May be useful to some.

PHP Code:
public void SendToSlack(const char[] cMessage)
{
    
char[] sFormat = new char[2048];
    
Format(sFormat2048"{\"channel\": \"#sourcemod\", \"username\": \"%s\", \"text\": \"%s\", \"icon_emoji\": \":speech_balloon:\"}""CSGO Server"cMessage);

    
Handle hHTTP_request SteamWorks_CreateHTTPRequest(k_EHTTPMethodPOST"https://hooks.slack.com/services/...");
    
SteamWorks_SetHTTPRequestRawPostBody(hHTTP_request"application/json"sFormatstrlen(sFormat));
    if (
hHTTP_request == null || !SteamWorks_SetHTTPCallbacks(hHTTP_requestSlack_Callback) || !SteamWorks_SendHTTPRequest(hHTTP_request))
    {
        
PrintToServer("[SendToSlack] SendToSlack failed to fire");
        
delete hHTTP_request;
    }
}

public 
Slack_Callback(Handle hRequestbool bFailurebool bRequestSuccessfulEHTTPStatusCode eStatusCode
{
    
char cActionName[64];
    
cActionName "Slack_Callback";
    if (!
bFailure && bRequestSuccessful)
    {
        switch (
eStatusCode)
        {
            case 
200:
            {
                
//all gud
            
}
            default:
            {
                
PrintToServer("[%s] failed with code [%i]"cActionNameeStatusCode);
                
SteamWorks_GetHTTPResponseBodyCallback(hRequestPrint_Response);
            }
        }
    }
    
delete hRequest;
}
public 
Print_Response(const char[] sData)
{
    
PrintToServer("[Print_Response] %s"sData);

__________________

Last edited by ImACow; 12-29-2016 at 15:40.
ImACow is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:55.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode