AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

How to use json string as output in rules?
 
 

I am using the chatscript to create a facebook messenger bot.
I would like to use a structured message (eg quick reply, button.. ) from Facebook Messenger Bots.
Can I use the following json string as the output statement in the Rule of the chatscript topic file (.top)?

t : {
recipient: {
id: recipientID
},
message: {
text: "some text",
quick_replies:[{
content_type:"text",
title:"Yes"
},{
content_type:"text",
title:"No"
}]
  }
}
}

Or should I use another method?
I would appreciate it if you could provide me with a guideline.
Thank you for reading!

 

 
  [ # 1 ]

Depends on what you expect the recipient to do with the response. Will facebook messenger, upon seeing that output do something useful with it. Certainly your message IS NOT LEGAL JSON, since you do not put double quotes around the object keys.

 

 
  [ # 2 ]

Hi Keunyoung

as far as I understand, for your purpose (drive FB Messenger “rich media” GUI from a CS program) you can use OOB messages processing.

See documentation:

* https://github.com/bwilcox-1234/ChatScript/blob/master/WIKI/ChatScript-Advanced-User-Manual.md#out-of-band-communication

* https://github.com/bwilcox-1234/ChatScript/blob/master/WIKI/ChatScript-Json.md#json—out-of-band-input-data


ChatScript basically exchange texts messages. Nevertheless you can also use “out of band” (OOB) messages just for your purpose.

Let say you want to put a FB Messneger “widget” like a button with label “OK”, you have to trap an OOB message, e.g.


# CS rule that output a OOB message to print a button with label “OK”

( ... ) [ button(“OK”)]


You have to insert a layer between the FB Messenger client and CS to translate an OOB command to a specific widget Messenger API


.———————————————.
| Messenger client adapter |
|——————————————- |
| GUI objects adapter       |
|——————————————- |
| ChatScript Client         |
.———————————————-.
  |
.———————————————.
| ChatScript Server       |
.———————————————-.
 

BTW, I’m working on a small CS client with some examples to do that (beforehand for Telegram):

https://github.com/solyaris/rChatScript

I hope this helps
regards/giorgio

 

 

 
  [ # 3 ]
Bruce Wilcox - Feb 27, 2017:

Depends on what you expect the recipient to do with the response. Will facebook messenger, upon seeing that output do something useful with it. Certainly your message IS NOT LEGAL JSON, since you do not put double quotes around the object keys.

Hi, Bruce Wilcox!
Thank you for your reply.
I created the json object and array with the ^ jsoncreate, ^jsonarrayinsert function yesterday,
And I tried to make the json string that I wanted by using dot notation as shown below.

u: (-testcase6) $$item_1 = ^jsoncreate(object)
 $
$item_1.id "receipient id string"
 
$$item_2 = ^jsoncreate(object)
 $
$item_21 = ^jsoncreate(object) 
 $
$item_22 = ^jsoncreate(object)
 $
$item_21.content__type "text"
 
$$item_21.title "Yes"
 
$$item_21.payload "DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_YES"
 
$$item_22.content__type "text"
 
$$item_22.title "No"
 
$$item_22.payload "DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_NO"
 
$$quickreply = ^jsoncreate(array)
 ^
jsonarrayinsert($$quickreply $$item_21)
 ^
jsonarrayinsert($$quickreply $$item_22)
 $
$item_2.text "select"
 
$$item_2.quick__replies = $$quickreply
 
$$item = ^jsoncreate(object) 
 $
$item.recipient = $$item_1
 
$$item.message = $$item_2
 
^jsonwrite( $$item \n
# ^jsontree( $$tmp ) \n 

I think I succeeded. But I do not know if I used the right way.
Hahaha
Perhaps I should do more chatscript study.

 

 

 
  [ # 4 ]
Giorgio Robino - Feb 27, 2017:

Hi Keunyoung

as far as I understand, for your purpose (drive FB Messenger “rich media” GUI from a CS program) you can use OOB messages processing.

See documentation:

* https://github.com/bwilcox-1234/ChatScript/blob/master/WIKI/ChatScript-Advanced-User-Manual.md#out-of-band-communication

* https://github.com/bwilcox-1234/ChatScript/blob/master/WIKI/ChatScript-Json.md#json—out-of-band-input-data


ChatScript basically exchange texts messages. Nevertheless you can also use “out of band” (OOB) messages just for your purpose.

Let say you want to put a FB Messneger “widget” like a button with label “OK”, you have to trap an OOB message, e.g.


# CS rule that output a OOB message to print a button with label “OK”

( ... ) [ button(“OK”)]


You have to insert a layer between the FB Messenger client and CS to translate an OOB command to a specific widget Messenger API


.———————————————.
| Messenger client adapter |
|——————————————- |
| GUI objects adapter       |
|——————————————- |
| ChatScript Client         |
.———————————————-.
  |
.———————————————.
| ChatScript Server       |
.———————————————-.
 

BTW, I’m working on a small CS client with some examples to do that (beforehand for Telegram):

https://github.com/solyaris/rChatScript

I hope this helps
regards/giorgio

 

 

Hi. Giorgio!
I sincerely appreciate your sincere reply.
I do not know what Out-Of-Band (OOB) data is.
I think I should study more by Googling and related articles that you provide.

 

 
  login or register to react
‹‹ Matching money      Harry’s Topic example ››