|
RobotServiceHostedOnWebServer
In this page, we will introduce a new feature to you which named 'AppEngine'. As you may not have your own server which allows you to connect to our platform directly by using our SDK, now there is another way to go, what you need is just a host on which your programs are deployed, and specify the URL in the admin page.(Use your SPID and password and sign in on http://botplatform.com, you will see the 'Web Host Service' option in 'Basic Information '). Note: If your SDK program already connects while you also provide the service for AppEngine, SDK is preferred. DetailsWhen you get ready for this, we will transer XML data through HTTP POST to the specified URL and get the HTTP response (also in XML format) to perform actions. We will post almost all of the 'Session Level' messages between your bot and your users to the specified URL. The XML's structure is clear and easy to understand (You may compare it with its corresponding Class file we difined in SDK), the 'type' attribute indicates the kind of the current message. Examples of our XML data for POST:
<request>
<robotId>bot@hotmail.com</robotId>
<userId>abc@hotmail.com</userId>
<sessionId>5257573032606033981</sessionId>
<action type="msg">
<fontStyle>0</fontStyle>
<fontName>Tohoma</fontName>
<fontColor>0</fontColor>
<text>some plain text</text>
</action>
</request>
<request>
<robotId>bot@hotmail.com</robotId>
<userId>abc@hotmail.com</userId>
<sessionId>5257573032606033981</sessionId>
<action type="fileevent">
<event>invite</event>
<transferId>{B1D11ABA-8608-45A5-BD91-1F1ABC685639}</transferId>
<size>4998</size>
<name>wiki.txt</name>
</action>
</request>
<request>
<robotId>bot@hotmail.com</robotId>
<userId>abc@hotmail.com</userId>
<sessionId>5257573032606033981</sessionId>
<action type="winkevent">
<digest>Wink digest</digest>
<name>Wink Name</name>
<size>30900</size>
</action >
</request>
<request> <robotId>bot@hotmail.com</robotId> <userId>abc@hotmail.com</userId> <sessionId>5257573032606033981</sessionId> <action type="inkmsg">ink data here</action> </request>
<request> <robotId>bot@hotmail.com</robotId> <userId>abc@hotmail.com</userId> <sessionId>5257573032606033981</sessionId> <action type="nudge" /> </request>
<request> <robotId>bot@hotmail.com</robotId> <userId>abc@hotmail.com</userId> <sessionId>5257573032606033981</sessionId> <action type="appevent">accept</action> </request> When posted, we expect the HTTP response. You may perform several actions per message(a HTTP request) if you obey the XML definition shown blow. Definition of the XML structure in HTTP response: <response>
<actions>
<action type="nudge" /><!-- send nudge -->
<action type="typing" /><!-- send typing -->
<action type="msg"><!-- send text message -->
<fontColor>CCCCCC</fontColor>
<fontStyle>10</fontStyle>
<fontName>Tahoma</fontName>
<text>hello(1) world(2)</text>
<emoticons>
<entry key="(1)" value="emo1.png" />
<entry key="(2)" value="emo2.png" />
</emoticons>
</action>
<action type="wink"><!-- send specified wink -->
<name>wink.cab</name>
<stamp>stamp of the wink, can be empty</stamp>
</action>
<action type="ink"><!-- send ink message -->
<data>base64 encoded ink data</data>
</action>
<action type="voice"><!-- send specified voiceclip -->
<name>voiceclip.wav</name>
</action>
<action type="filecmd"><!-- when a user sends a file to your bot -->
<cmd>accept</cmd><!-- accept or reject -->
<transferId>tid</transferId>
<saveUrl>http://example.saveurl.com</saveUrl><!-- for accept command only -->
</action>
<action type="file"><!-- send a specified file to your users -->
<name>file.pdf</name>
</action>
<action type="app"><!-- open activity window -->
<name>BotPlatform</name>
<data>http://botplatform.com</data>
</action>
</actions>
</response>Sample code (A simple Java Servlet for AppEngine service) : try {
ServletInputStream is = this.request.getInputStream();
SAXBuilder builder = new SAXBuilder();
Document doc = null;
try {
doc = builder.build(is);
} catch (JDOMException e) {
e.printStackTrace();
return NONE;
} finally {
is.close();
}
Element request = doc.getRootElement();
Element action = request.getChild("action");
String type = action.getAttributeValue("type");
String response = null;
if ("nudge".equals(type)) {
response = "<response><actions><action type=\"nudge\"/></actions></response>";
} else if ("fileevent".equals(type)) {
if ("invite".equals(action.getChildText("event"))) {
Random ran = new Random();
String tid = action.getChildText("transferId");
int ranInt = ran.nextInt(2);
if (0 == ranInt) {
response = "<response><actions><action type=\"filecmd\"><cmd>accept</cmd><transferId>"
+ tid
+ "</transferId></action></actions></response>";
} else if (1 == ranInt) {
response = "<response><actions><action type=\"filecmd\"><cmd>reject</cmd><transferId>"
+ tid
+ "</transferId></action></actions></response>";
}
}
} else if ("winkevent".equals(type)) {
response = "<response><actions><action type=\"wink\"><name>wink.dat</name><stamp>stamp could be empty</stamp></action></actions></response>";
} else if ("inkmsg".equals(type)) {
response = "<response><actions><action type=\"ink\"><data>ink data here(Base64 encoded)</data></action></actions></response>";
} else if ("msg".equals(type)) {
String content = action.getChildText("text");
if ("voice".equals(content))
response = "<response><actions><action type=\"voice\"><name>voiceclip.wav</name></action></actions></response>";
else if ("app".equals(content))
response = "<response><actions><action type=\"app\"><name>BotPlatform</name><data>http://botplatform.com</data></action></actions></response>";
else if ("file".equals(content))
response = "<response><actions><action type=\"file\"><name>demo.txt</name></action></actions></response>";
else if ("typing".equals(content))
response = "<response><actions><action type=\"typing\" /></actions></response>";
else
response = "<response><actions><action type=\"msg\">"
+ " <fontColor>CCCCCC</fontColor><fontStyle>10</fontStyle><fontName>Tahoma</fontName><text>中文hello(1)world(2)</text>"
+ "<emoticons><entry key=\"(1)\" value=\"emo1.png\" /><entry key=\"(2)\" value=\"emo2.png\" /></emoticons>"
+ "</action></actions></response>";
} else if ("appevent".equals(type)) {
response = "<response><actions><action type=\"msg\"><text>App Window Activity</text></action></actions></response>";
} else {
response = "<response><actions><action type=\"msg\"><text>"
+ type
+ " occurs...but do nothing</text></action></actions></response>";
}
if (response != null)
appendResponse(response);
} catch (IOException e) {
e.printStackTrace();
}
return NONE;
|
Hello Guys,
I'm trying to get the XML send to you. I'm using PHP, how can I do that? My php can send the XML back to the bot, but I cant read the XML recieved of the bot. Someone could help me?
Please check the following: 1. You should tell the botplatform your service url. This can be down in the botplatform.com admin page. 2. You should also ensure the url is valid and accessible.(the unaccessible urls include "http://127.0.0.1/...","http://localhost/..." etc.) 3. If your SDK program already connects while you also provide the service url, SDK is preferred.
Hello Boyce, Thanks for the answer. I already did the bellow, I told to the botplataform my URL and it is accessible. (http://www.xquad.com.br/messenger/) And I didn’t have a SDK program, so I didn’t believe that the problem is not the point 3.
Look this is my bot mainframe(at)xquad(dot)com(dot)br Try to talk with it; you will see that it answers you. I can send to you (botplataform) my answers. What I not know how to do is get the answer of botplataform to me. Like what the user typed to the bot, etc.
In the documentation you said that “we will transfer XML data through HTTP POST to the specified URL”. This XML data is that I’m not able to take. You are literally posting the XML to my URL http://www.xquad.com.br/messenger/ ? If yes, what is the name of the field where you are posting the XML?
Best, Flávio
The post request content-type is application/xml(not application/x-www-form-urlencoded). So you should read the entire body as the xml data, you couldn't read any parameters.
Unfortunately I believe that is no possible to get the XML that you post using php. Do you know some that are using PHP for that and could help me?
Best, Flávio
Hello. Is there a way to Push Messages via HTTP? That would be wonderful! :)