Different objects sent to the bot
Every time a message is sent from the user to the bot, these objects are sent in the JSON format to the event parameter of handler methods inside the IDE Bot Builder.
Object Name | Sample Value | Description | Remarks |
---|---|---|---|
contextobj | {"botname":"demobot", "channeltype":"twitter", "contextid":"john", "contexttype":"p2p"} | JSON object defining various parameters and ways of conversation. | channeltype - the messaging channel name from where the user interacts with the bot. contextid / channelid - The user id of a user on the particular messaging channel. contexttype - The type of conversation. |
senderobj | {"channelid":"john", "channeltype":"twitter", "display":"John Doe"} | JSON object identifying the user details. This is useful in the case of a group on a messaging channel. | |
messageobj | {"text":"Hi", "type":"msg"} | JSON object for messages from the user. | |
channel | The channel from where the user is interacting with the bot. | ||
botname | demobot | The name of the bot. | |
sender | 195173 | This is the user id of the user on the messaging channel who has started the conversation with the bot. | |
message | Hi | The message sent by the user to the bot. |
These are the properties to access the objects in the IDE Bot Builder.
Property Name | Description |
---|---|
event.message | Returns the message from the user to the bot. This can be text or image URL or location URL etc. |
event.sender | Returns the user id of the user from the messaging channel. |
event.channel | Returns the messaging channel name from where the user is conversing with the bot. |
event.botname | Returns the name of the bot. |
event.senderobj.channelid | Returns the user id of the user from the messaging channel. |
event.senderobj.channeltype | Returns the messaging channel name from where the user is conversing with the bot. |
event.senderobj.display | Returns the display name of the user on a messaging channel from where he/she is conversing with the bot |
event.messageobj.text | Returns the message from the user to the bot. This can be text or image URL or location URL etc. |
event.messageobj.type | Returns the message type from the user. It can be msg or image or location etc. |
event.messageobj.latitude | Returns the latitude of the location sent by the user to the bot. |
event.messageobj.longitude | Returns the longitude of the location sent by the user to the bot. |
event.messageobj.address | Returns the address of the location sent by the user to the bot. |
event.messageobj.url | Returns the image URL of the image sent by the user to the bot. |
event.contextobj.botname | Returns the name of the bot. |
event.contextobj.channeltype | Returns the messaging channel name from where the user is conversing with the bot. |
event.contextobj.contextid | Returns the user id of the user from the messaging channel. |
event.contextobj.contexttype | Returns the type of conversation. |
event.getresp | Returns the response of an HTTP/HTTPs call into the HttpResponseHandler function. |
event.dbval | Returns the response of the database call into the DbGetHandler or DbPutHandler function. |
event.params | Returns the URL parameters sent to the bot through an HTTP call to the bot. For example - if one of the parameters is "message" then to access it use 'event.params.message' in the HttpEndpointHandler function. |
Sample JSON for text message
{
"botname": "demobot",
"contextobj": {
"botname": "demobot",
"channeltype": "fb",
"contextid": "1951021",
"contexttype": "p2p"
},
"messageobj": {
"text": "Hi",
"type": "msg"
},
"senderobj": {
"channelid": "1951021",
"channeltype": "fb",
"display": "John"
},
"channel": "fb",
"sender": "1951021",
"message": "Hi"
}
Sample JSON for location from the user
{
"botname": "demobot",
"contextobj": {
"botname": "demobot",
"channeltype": "telegram",
"contextid": "195173611",
"contexttype": "p2p"
},
"messageobj": {
"address": "",
"latitude": "19.145313",
"longitude": "72.855748",
"text": "https://www.google.com/maps/?q=19.145313,72.855748",
"type": "location"
},
"senderobj": {
"channelid": "195173611",
"channeltype": "telegram",
"display": "Shreyans"
},
"channel": "telegram",
"sender": "195173611",
"message": "https://www.google.com/maps/?q=19.145313,72.855748"
}
Sample JSON for image from the user
{
"botname": "rildemo",
"contextobj": {
"botname": "demobot2",
"channeltype": "telegram",
"contextid": "195173611",
"contexttype": "p2p"
},
"messageobj": {
"imgData": "{\"botname\":\"rildemo\",\"contextObj\":{\"botname\":\"demobot2\",\"channeltype\":\"telegram\",\"contextid\":\"195173611\",\"contexttype\":\"p2p\"},\"url\":\"https://api.telegram.org/file/bot183230543:AAHr9nQwmXVsGZzS8zk6gd-bd0pBC_kl5N4/photo/file_119.jpg\"}",
"text": "https://api.telegram.org/file/bot183230543:AAHr9nQwmXVsGZzS8zk6gd-bd0pBC_kl5N4/photo/file_119.jpg",
"type": "image",
"url": "https://api.telegram.org/file/bot183230543:AAHr9nQwmXVsGZzS8zk6gd-bd0pBC_kl5N4/photo/file_119.jpg"
},
"senderobj": {
"channelid": "195173611",
"channeltype": "telegram",
"display": "Shreyans"
},
"channel": "telegram",
"sender": "195173611",
"message": "https://api.telegram.org/file/bot183230543:AAHr9nQwmXVsGZzS8zk6gd-bd0pBC_kl5N4/photo/file_119.jpg"
}
Updated almost 2 years ago