|
|
Member
Total posts: 13
Joined: Mar 1, 2018
|
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: http://services.groupkt.com/state/search/USA?text=alabama
{
"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: http://services.groupkt.com/state/search/USA?text=alaska
{
"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 = ^”\“services.groupkt.com/state/search/USA?text=$$tmp”“
$$user_agent = ^“myemail@hotmail.com User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)”
$$tmp = ^jsonopen(GET $$url “” $$user_agent)
$$tmp.result.capital 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.
|
|
|
|
|
Posted: Apr 10, 2018 |
[ # 1 ]
|
|
Moderator
Total posts: 2372
Joined: Jan 12, 2010
|
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)
|
|
|
|
|
Posted: Apr 10, 2018 |
[ # 2 ]
|
|
Member
Total posts: 13
Joined: Mar 1, 2018
|
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 = ^”\“services.groupkt.com/state/search/USA?text=$_tmp”“
$_userAgent = ^“User-Agent: %bot, ChatScript”
$_header = ^” ~Accept: application/json
$_userAgent
~Content-Type: application/json “
$_tmp = ^jsonopen(transient get $_url NULL $_header)
$_tmp.result.capital 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.
|
|
|
|
|
Posted: Apr 10, 2018 |
[ # 3 ]
|
|
Moderator
Total posts: 2372
Joined: Jan 12, 2010
|
have you tried it with :trace json enabled?
|
|
|
|
|
Posted: Apr 10, 2018 |
[ # 4 ]
|
|
Moderator
Total posts: 2372
Joined: Jan 12, 2010
|
and maybe irrelevant and maybe not, make your url be https:// or http://
|
|
|
|
|
Posted: Apr 10, 2018 |
[ # 5 ]
|
|
Member
Total posts: 13
Joined: Mar 1, 2018
|
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.
|
|
|
|
|
Posted: Apr 10, 2018 |
[ # 6 ]
|
|
Moderator
Total posts: 2372
Joined: Jan 12, 2010
|
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.
|
|
|
|
|
Posted: Apr 10, 2018 |
[ # 7 ]
|
|
Member
Total posts: 13
Joined: Mar 1, 2018
|
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.
|
|
|
|
|
Posted: Apr 10, 2018 |
[ # 8 ]
|
|
Moderator
Total posts: 2372
Joined: Jan 12, 2010
|
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?
|
|
|
|
|
Posted: Apr 10, 2018 |
[ # 9 ]
|
|
Member
Total posts: 13
Joined: Mar 1, 2018
|
Hi Bruce,
I have mailed you the user log. I am running it locally as of now. Kindly check the log.
|
|
|
|
|
Posted: Apr 11, 2018 |
[ # 10 ]
|
|
Senior member
Total posts: 103
Joined: Oct 17, 2017
|
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.
|
|
|
|
|
Posted: Apr 12, 2018 |
[ # 11 ]
|
|
Senior member
Total posts: 200
Joined: Jan 12, 2016
|
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.
|
|
|
|
|
Posted: Apr 12, 2018 |
[ # 12 ]
|
|
Moderator
Total posts: 2372
Joined: Jan 12, 2010
|
“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.
|
|
|
|
|
Posted: Apr 12, 2018 |
[ # 13 ]
|
|
Member
Total posts: 13
Joined: Mar 1, 2018
|
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.
|
|
|
|
|
Posted: Apr 12, 2018 |
[ # 14 ]
|
|
Moderator
Total posts: 2372
Joined: Jan 12, 2010
|
please email direct to the gmail given at the start of all cs documentation.
|
|
|
|
|
Posted: Apr 12, 2018 |
[ # 15 ]
|
|
Member
Total posts: 13
Joined: Mar 1, 2018
|
I have mailed you the log to the gmail id given in cs documentation.
|
|
|
|