Contents

Support Managers

Xartashah
English
online
Aerielle Kiyori
English
offline
show offline managers  
English, Hindi, Russian  

SSTI API Example


The following script is being used as SSTI API testing suite. It provides the easy way to understand and test the API.

////////////////////////////////////////////////////////////////////////////////
// SmartShare Tenant Inviter example plugin
// (C) Advers Inc, 2013
// http://www.mysmartbots.com/docs/SSTI
 
// This script demonstrates the API usage and interaction with SSTI. Feel free to
// modify and distribute.
 
// CONSTANTS: Copy them to your script to call SSTI API
// See http://www.mysmartbots.com/docs/SSTI_API for details
// Messages to SSTI (commands):
integer SSTI_API_GET_GUESTS=-45030001;
integer SSTI_API_CUSTOM_BUTTON=-45030002;
 
// Replies from SSTI (events):
integer SSTI_EVENT_INITIALIZED=-45040001;
integer SSTI_EVENT_GUESTS=-45040002;
integer SSTI_EVENT_CUSTOM_BUTTON=-45040003;
integer SSTI_EVENT_NEW_TENANT=-45040004;
 
 
integer CHANNEL=-123456;
integer touch_started=0;
 
string STR_TEST_GUESTS="Get guests";
string STR_TEST_BUTTON="Custom btn";
 
default {
    state_entry() {
        llListen(CHANNEL,"",NULL_KEY,"");
    }
 
    // Click and hold for API test menu
    touch_start(integer total_number) {
        llWhisper(0,"SSTI API test suite: keep pressing for 2 seconds to open debug menu");
        touch_started=llGetUnixTime();
    }
    touch(integer total_number) {
        if(touch_started<llGetUnixTime()-1) {
            llDialog(llDetectedKey(0),"Choose the test function:",
                [STR_TEST_GUESTS,STR_TEST_BUTTON],CHANNEL);
        }
    }
 
    // This function does the calls to SSTI
    listen(integer channel, string name, key id, string msg) {
        if(msg==STR_TEST_GUESTS) {
            llWhisper(0,"Calling SSTI_API_GET_GUESTS...");
            llMessageLinked(LINK_SET,SSTI_API_GET_GUESTS,"",NULL_KEY);
        }
 
        if(msg==STR_TEST_BUTTON) {
            llWhisper(0,"Calling SSTI_API_CUSTOM_BUTTON");
            llMessageLinked(LINK_SET,SSTI_API_CUSTOM_BUTTON,"API test",NULL_KEY);
        }        
    }
 
    // This function processes the replies from SSTI
    link_message(integer sender, integer cmd, string str, key id) {
        // React on initialization
        if(cmd==SSTI_EVENT_INITIALIZED) {
            llWhisper(0,"SSTI API: initialization complete, group name: "+
                str);
        }
 
        // React on guests reply
        if(cmd==SSTI_EVENT_GUESTS) {
            // Parse reply to guests list. This code is given as a code
            // template for your scripts:
            list guestNames; // Store names here
            list guestKeys; // Store keys here
            list guestType; // Type: G for guest, P for partner
 
            list source=llParseString2List(str,["&"],[]);
            integer i;
            for(i=0;i<llGetListLength(source);i+=3) {
                guestNames+=[llList2String(source,i)];
                guestKeys+=[llList2Key(source,i+1)];
                guestType+=[llList2String(source,i+2)];
            }
 
            // Compose the readable guests list
            string result="";
            for(i=0;i<llGetListLength(guestKeys);i++) {
                result+=llList2String(guestType,i)+" "+
                    llList2String(guestKeys,i)+" "+
                    llList2String(guestNames,i)+"\n";
            }
 
            llWhisper(0,"SSTI API:\n"+
                "tenant UUID: "+(string)id+"\n"+
                "guests list:\n"+result);
        }
 
        // React on custom button press
        if(cmd==SSTI_EVENT_CUSTOM_BUTTON) {
            llWhisper(0,"SSTI API: custom button pressed by "+(string)id);
        }        
 
        // React on new tenant event
        if(cmd==SSTI_EVENT_NEW_TENANT) {
            llWhisper(0,"SSTI API: new tenant "+str+" ("+(string)id+")");
        }        
 
    }
}