Sending Group Notice

From SmartBots Developers Docs
Jump to: navigation, search

The following example demonstrates the usage of send_notice API command.

At touch it sends a notice to the group.

string sbApiKey="...";
string sbBotName="Fashion Firethorn";
string sbBotAccessCode="nskndKgfa-243js";

key httpReq=NULL_KEY;

default {
    touch_start(integer total_number) {
        string params = llDumpList2String([
            "action="  + "send_notice",
            "apikey="  + llEscapeURL(sbApiKey),
            "botname=" + llEscapeURL(sbBotName),
            "secret="  + llEscapeURL(sbBotAccessCode),
            "groupuuid="  + "877d11f0-72ad-649e-3ba2-96185b72d345",
            "subject=" + llEscapeURL("Notice subject"),
            "text=" + llEscapeURL("Notice text goes here")
            ],"&");

        httpReq=llHTTPRequest("https://api.mysmartbots.com/api/bot.html",
            [HTTP_METHOD,"POST"], params);
    }
    
    // This event is required only if you want to process the SmartBots's reply
    http_response(key request_id, integer status, list metadata, string body) {
        if(request_id!=httpReq) return;
        
        // Store result here
        string result;
        string action="";
        string resulttext="";
        
        // Parse server reply
        list pairs=llParseString2List(body,["&"],[]);
        integer i=0;
        for(i=0;i<llGetListLength(pairs);i++) {
            list keyv=llParseString2List(llList2String(pairs,i),["="],[]);
            string keyname=llList2String(keyv,0);
            string value=llUnescapeURL(llList2String(keyv,1));
            
            if(keyname=="result")       result=value;
            if(keyname=="resulttext")   resulttext=value;
            if(keyname=="action")       action=value;
        }
        
        if(result=="FAIL") {
            llOwnerSay("Command '"+action+"' failed: "+resulttext);
        }
    }    
}