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..

External API call in ChatScript Bot
 
 
  [ # 16 ]

looking at your log, I see that you ask the same question twice in a row “what is sap” and it answers fine the first time and says “I dont know what to say” the second. Presumably you do not have the topic flag KEEP on your topic, so responders get erased after use. You should enable KEEP for faq-style questions (assuming user might ask same question again).

Similarly you need REPEAT on a topic if you get same answer within 20 volleys.

So I’m guessing “what is capital of alabama” fails because the rule has been consumed.
Your log shows no call to JSON for that input. But the input “who is gandi” does go to json and return, so basic jsonopen is functioning.

Try doing
erase the contents of the USER folder (not the folder itself)
:reset
:trace all
What is the capital of alabama
and send me that log if it fails.

 

 
  [ # 17 ]

Hi Bruce,

Sorry for replying late. I have made the changes which you suggested. But still it is failing to make the external call. I have mailed you the log. Kindly let me know what i can do to resolve this issue.

Thanks,
Kaushik

 

 
  [ # 18 ]

Hi Bruce,

Any update on the log which i mailed you?

Thanks,
Kaushik

 

 
  [ # 19 ]

The trace shows you have mistyped your pattern.


pattern: ( what is capital of _* 1 > )


You need (what is capital of _*1 >) without space after the *

 

 
  [ # 20 ]

When I looked into your log file, I saw this:
...,....Topic: ~keywordless linear Questions:
....,....
....,....,try u:5.0 @0:  sample: #! What is Capital?      pattern: ( what is capital of _* 1 > )
....,....,( what+ is+ capital+ of+ _* 1-

where your sample input made it easy to locate this rule, and the trace shows it found what+ and is+ and capital+ and of+ and _*  and failed to detect 1 (-)

 

 
  [ # 21 ]

Hi Bruce,

I have updated the code according to the suggestion (what is capital of _*1 >) without space after the *
But still facing the issue in external api call. On going through log , it shows that it failed to connect JSON call.
Can you please suggest what else need to be done?.

I have mailed you the Keywordless.top file and log file. Kindly help

Thanks,
Kaushik

 

 
  [ # 22 ]

Thanks for the top file, it was helpful..  The following code works. It varies from yours by a) using different parameter API call to them (i hardcoded my state code, you would have to transcribe between user input and state code.  b) I added http:// in front of web address. c) the answer has a bit more nesting than you had.  d) I used a standard header that clearly gets the accept/contenttype correct for json. Yours was returning html data instead. Hopefully this will clue you in enough. The wiki documentation gave you a sample url (in that case http:// prefixed), and you didnt follow its style.

outputmacro: ^getheader()
  return (^“Content-Type: application/json
  ~User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64)
  ~Cache-Control: no-cache
  ~Accept: application/json
  ~Accept-Encoding: identity,*;q=0
  ~Accept-Language: en-US,en;q=0.9”)

topic: ~introductions keep()
t: HI.^keep()

#! What is Capital? 
u: (capital of _*1 >) ^keep() repeat() $_tmp=_0
$_statename = $_tmp
$_url = ^‘http://services.groupkt.com/state/get/USA/AL’
$_userAgent = ^“User-Agent: %bot, ChatScript”
$_header = ^getheader()
$_tmp = ^jsonopen(transient get $_url NULL $_header)
$_tmp.RestResponse.result.capital is the capital of $_statename\n

 

 

 
  [ # 23 ]

Hi Bruce,

Thanks for all the help that you are providing in solving my external api call issue.

We ran the code which you gave, hard coded the AL . It returns correctly. But we want user to ask the question. Like “capital of alabama?” or “capital of alaska”.. so we need the dynamic link for that. As per your suggestion we made changes in the dynamic link. It is making JSON call but while going through the trace log, we saw that it return ” “(empty) for the answer.

#! What is Capital?  
u: (capital of _*1 >) ^keep() repeat() $_tmp=_0
$_statename = $_tmp
$_url = ^”\“http://services.groupkt.com/state/search/USA?text=$_tmp\”“
$_userAgent = ^“User-Agent: %bot, ChatScript”
$_header =^” ~Accept: application/json ~Cache-Control: no-cache ~Content-Type: application/json ~User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64)~Accept-Encoding: identity,*;q=0~Accept-Language: en-US,en;q=0.9 “
$_tmp = ^jsonopen(transient get $_url NULL $_header)
$_tmp.RestResponse.result.capital is the capital of $_statename\n

e.g. for alabama…it returns…        is the capital of alabama.

Can you please help. Kindly let us know what is the issue and can we solve it.

I have mailed you the top file and log file. Please check.


 

 
  [ # 24 ]

The $_url assignment should be:
$_url = ^”http://services.groupkt.com/state/search/USA?text=$_tmp“

Your version had wrapped the URL in quotes, which is an invalid URL.

 

 
  [ # 25 ]

Hi guys ! I am trying to get familiar with using json commands within chatscript and i actually copied the code that Bruce have sent just above. But for some reason i am running into error. Can anyone tell me why is it happening ?
It is exactly the same code.

ERROR SUMMARY:
  line 7 of capital.top:
^”http://services.groupkt.com/state/search/usa?text=$_tmp“ either references a function w/o arguments or names a function variable that doesn’t exist

1 errors - press Enter to quit. Then fix and try again.

 

 
  [ # 26 ]

a) try noncurly quotes
b) try simple ’  character instead of quotes

but I expect its the curly quotes.
But I dont see the full line, so I’m guessing

 

 
  [ # 27 ]

Thank you very much Bruce for your fast reply !

It was the quotes. Cant use curly quotes.

Thank you very much !

 

 < 1 2
2 of 2
 
  login or register to react