Reply to menu dialog

This script demonstrates how to use the reply_dialog API command.
It performs the following actions:

  • Waits until you touch it

  • Sends a dialog window to your bot

  • Reports the bot’s menu selection back to you

Place this code in an in-world object and replace the variables at the beginning with your own values.


string sbApiKey = "...";
string sbBotName = "YourBotName Resident";
string sbBotAccessCode = "bot-access-code";

// Hint: sbBotName is the bot's name. However, you can place
// your SL name here to see the dialog yourself (and even touch the button).
// Obviously, HTTP API won't make you touch the menu automatically :)

key httpReq = NULL_KEY;
integer CHANNEL = -11;

default {
    touch_start(integer total_number) {
        llOwnerSay("Searching for UUID, bot "+sbBotName);
        
        // Look for bot nearby (we can use HTTP API name2key here, too)
        llSensor(sbBotName, NULL_KEY, AGENT, 96, PI);
    }
    
    sensor(integer num) {
        // We've detected our bot!
        // Hint: If "Found" message does not appear,
        // check that the bot is within 96 meters range.
        key id = llDetectedKey(0);
        llOwnerSay("Found bot UUID: "+ (string)id +
                ", sending dialog menu and waiting 3 seconds...");
        
        // Sending dialog to the bot
        llListen(CHANNEL, sbBotName, NULL_KEY, "");
        llDialog(id, "Are you human or bot?", ["human", "bot", "both"], CHANNEL);
        
        // Wait 3 seconds and then make bot reply
        llSetTimerEvent(3);
    }
    
    timer() {
        llOwnerSay("Now sending HTTP command to the bot " +
                "to click the menu's item 'bot'...");
        
        // The HTTP API command is being sent here:
        string params = llDumpList2String([
            "action="  + "reply_dialog",
            "apikey="  + llEscapeURL(sbApiKey),
            "botname=" + llEscapeURL(sbBotName),
            "secret="  + llEscapeURL(sbBotAccessCode),
            
            "channel="  + (string)CHANNEL,
            "object=" + (string)llGetKey(),
            "button=" +  llEscapeURL("bot")
            ], "&");
 
        llHTTPRequest("https://api.mysmartbots.com/api/bot.html",
            [HTTP_METHOD, "POST"], params);
            
        llSetTimerEvent(0);
    }
    
    listen(integer channel, string name, key id, string message) {
        // We've got a reply from the menu!
        llOwnerSay("Bot touched the menu item: " + message);
    }
}

Important Note

This example is a simplified demonstration.
In practice, you might need to handle:

  • When the bot actually receives a popup dialog

  • The channel that dialog uses (since it can vary each time)