Corrade can be used to answer dialogs by clicking buttons once it gets a popup. In order to do this, the following operations must be performed:
dialog
notifications and receive the data. llDialog
, Corrade will post the data to the specified notification URL
.replytodialog
can be sent to Corrade in order to reply to this dialog. the required parameters for the replytodialog
command are the channel
that the dialog was sent on, the button
to press, the index
of the button and the item
UUID
that sent the dialog.
Binding to dialog notifications can be done in a script by sending the notify
command to Corrade along with the action
set to set
, the type
to dialog
and an URL
where to send dialogs that Corrade receives to:
llInstantMessage(CORRADE, wasKeyValueEncode( [ "command", "notify", "group", GROUP, "password", PASSWORD, "action", "set", "type", "dialog", "URL", wasURLEscape(URL) ] ) );
Suppose you have a script that sends a dialog to Corrade, such as:
default { touch_start(integer num) { // Corrade's UUID key CORRADE = (key)"a1c0720f-082f-4d6a-bc51-5457f16f05f3"; // Listen on channel -30 for the reply. llListen(-30, "", "", ""); // Send the dialog to Corrade. llDialog(CORRADE, "Hello, please click some buttons!", [ "A", "B" ], -30); } listen(integer channel, string name, key id, string message) { llOwnerSay("Got dialog button: " + message); } }
when Corrade receives the dialog, provided that you have bound to dialog
notifications like we did in the previous step, then Corrade will send the dialog data to the notification URL
. Here is an example of the data received by Corrade when Corrade receives a dialog:
type=dialog&message=Hello, please click some buttons!&firstname=Sexy&lastname=Joe&channel=-30&name=Object&item=b85a01bc-2a81-e31d-a728-b573a7674e6e&owner=1ad33407-a792-476d-a5e3-06007c0802bf&button=Index,0,A,1,B
In case the URL
is the URL
of a script, we can process the dialog data using http_request
:
http_request(key id, string method, string body) { // always confirm to Corrade that the message // has been properly received by the callback llHTTPResponse(id, 200, "Ok"); // get the UUID of the object sending the dialog key item = (key)wasURLUnescape( wasKeyValueGet( "item", body ) ); // get the channel that the dialog was sent on integer channel = (integer)wasURLUnescape( wasKeyValueGet( "channel", body ) ); // get the buttons that the dialog has list buttons = llList2ListStrided( llDeleteSubList( wasCSVToList( wasURLUnescape( wasKeyValueGet( "button", body ) ) ), 0, 1 ), 0, -1, 2 ); // let's pick the second button to click: string button = llList2String(buttons, 1); // since it's the second button, index is 1 integer index = 1; // and now send the command to Corrade to click // the second button llInstantMessage(CORRADE, wasKeyValueEncode( [ "command", "replytoscriptdialog", "group", wasURLEscape(GROUP), "password", wasURLEscape(PASSWORD), "channel", channel, "button", wasURLEscape(button), "index", index, "item", wasURLEscape(item), "URL", wasURLEscape(URL) ] ) ); }