Difference between revisions of "HTTP API/Examples/Reply to menu dialog"
From SmartBots Developers Docs
Line 7: | Line 7: | ||
# Reports the bot menu selection to you | # Reports the bot menu selection to you | ||
− | Place this code to an in-world object, and replace variables at the beginning with your values (read more about [[Developer's API key|api key]] and [ | + | Place this code to an in-world object, and replace variables at the beginning with your values (read more about [[Developer's API key|api key]] and [https://mysmartbots.com/docs/Bot_access_code Bot access code]); |
=== LSL Code === | === LSL Code === | ||
Line 63: | Line 63: | ||
], "&"); | ], "&"); | ||
− | llHTTPRequest(" | + | llHTTPRequest("https://api.mysmartbots.com/api/bot.html", |
[HTTP_METHOD, "POST"], params); | [HTTP_METHOD, "POST"], params); | ||
Latest revision as of 14:01, 7 September 2017
This script does the following:
- Waits until you touch it
- Sends the dialog window to your bot
- Reports the bot menu selection to you
Place this code to an in-world object, and replace variables at the beginning with your values (read more about api key and Bot access code);
LSL Code
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).
// Obliviously, HTTP API won't make you touching 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 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 menu!
llOwnerSay("Bot touched the menu item: " + message);
}
}
Important note
Actually the script is not complete. You may need to know:
- the moment WHEN bot gets a popup menu
- the channel that menu uses (since menu's channel can vary)
This example is very basic (you can use it when you exactly know that dialog has been shown, and a dialog's channel). New HTTP API callback functions (in development yet) will allow you to get that info from bots.