AI Zone Admin Forum Add your forum

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

External API call in ChatScript Bot

Hi All,

I am trying to perform external api call in the chatscript’s chatbot. The data structure from which i wish to get data is like the following:

For Alabama - url:
"RestResponse" : {
"messages" : [ "Total [1] records found." ],
"result" : [ {
"id" : 1,
"country" : "USA",
"name" : "Alabama",
"abbr" : "AL",
"area" : "135767SKM",
"largest_city" : "Birmingham",
"capital" : "Montgomery"
} ]
Similarly for Alaska url:
"RestResponse" : {
"messages" : [ "Total [1] records found." ],
"result" : [ {
"id" : 2,
"country" : "USA",
"name" : "Alaska",
"abbr" : "AK",
"area" : "1723337SKM",
"largest_city" : "Anchorage",
"capital" : "Juneau"
} ]
I have written the following code .But its not making the API call.
When user enters “what is capital of Alabama”,it should reply back ” Montgomery is capital of Alabama”

u: (what is capital of _* 1 >) ^keep() repeat() $$tmp=_0
$$statename = $$tmp
$$url = ^”\“$$tmp”“
$$user_agent = ^“[email protected] User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)”
$$tmp = ^jsonopen(GET $$url “” $$user_agent)
$$ is the capital of $$statename \n

Kindly let me know where am i going wrong and what can i do to make external api call happen.


  [ # 1 ]

Your arguments to ^jsonOpen are not correct. Your first arg needs to be a persistance of data.
Your $$user_agent is also not legal header notation (that I know of) because the email address is not a std notation. Such notation always has type: followed by data, like below

$_headers = ^“Content-Type: application/x-www-form-urlencoded
  ~User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64)
  ~Cache-Control: no-cache
  ~Accept: */*
  ~Accept-Encoding: identity,*;q=0
  ~Accept-Language: en-US,en;q=0.9”

^jsonopen(transient get $_url NULL $_headers)


  [ # 2 ]

Hi Bruce,

As per your suggestion , I have changed the code to the following:

u: (what is capital of _* 1 >) ^keep() repeat() $_tmp=_0
$_statename = $_tmp
$_url = ^”\“$_tmp”“
$_userAgent = ^“User-Agent: %bot, ChatScript”
$_header = ^” ~Accept: application/json
            ~Content-Type: application/json “
$_tmp = ^jsonopen(transient get $_url NULL $_header)
$ is the capital of $_statename\n

But still , same issue . It is not making the external api call for the capital.
Kindly let me know if something more to be corrected.


  [ # 3 ]

have you tried it with :trace json   enabled?


  [ # 4 ]

and maybe irrelevant and maybe not, make your url be https:// or http://


  [ # 5 ]

Hi Bruce,
I cant use https:// , its not opening the page. I updated the url with http://. But no change , still no expected results.
After running-
:trace json

Enabled simple: echo
Enabled deep detail: json
Disabled simple: match ruleflow variables
Disabled mild detail: output pattern input prepare
Disabled deep detail: always fact hierarchy infer label macro pos query sample sql substitute tcp topic user userfact treetagger usercache varassign
trace = 553648129 (0x21000001).

Please let me know if I am doing something wrong.


  [ # 6 ]

Yeah, AFTER you have done :trace json, on your NEXT input which is your failing input, you will get a trace of what the system tried to do.


  [ # 7 ]

Respond: user:kaushik bot:mybot ip: (~introductions) 162   what is capital of alabama ==> I don’t remember.  When:Apr10’18-22:31:30 Why:~honest_response.33.0.~quibble_all.12.0   F:32 . It showed me this when i asked it about capital of alabama.


  [ # 8 ]

That is what you get in a server log or a user log without trace enabled. With trace turned on, the user log should show much more (and you will see it in console). Are you running locally or as a server.  Can you email me your user log file?


  [ # 9 ]

Hi Bruce,

I have mailed you the user log. I am running it locally as of now. Kindly check the log.


  [ # 10 ]

My $.02

Can you make the correct call with curl?

If so, then use wireshark to capture the actusl call that curl made.

Then use wireshsrk to see what chatscript tried to send.

I suspect you are getting the quibble because the jdonopen call is failing. Try putting log() before and after to see.

In a side note, i have had trouble with transient option, it seems to always blow up.

Stephen g.


  [ # 11 ]

We make ^jsonopen() calls with transient all the time, so I doubt that is a problem.

permanent vs transient just affects the label of the json object - whether a “t” is added or not.


  [ # 12 ]

“I have mailed you the user log. I am running it locally as of now. Kindly check the log. “

I have not seen it in my email.



  [ # 13 ]

Hi Bruce,

I have sent you the userlog 2 days back on this website only. There is an option : Email Bruce. It redirects to a page . I sent the log from there. If you want me to send the log again . Kindly let me know the email on which to contact you.


  [ # 14 ]

please email direct to the gmail given at the start of all cs documentation.


  [ # 15 ]

I have mailed you the log to the gmail id given in cs documentation.


 1 2 > 
1 of 2
  login or register to react