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 connect to an external API
 
 

Hi
I’m trying to connect to an external API

For example, if you have a weather chatbot, the chatscript server itself does not have weather data, so it should be retrieved from an external server.

You need to parse the name of the region you entered, for example city, country, village.

And then, you should call api


But I don’t know how to do..

I saw this syntax in the keywordless.top file in Harry’s folder

Whether I need to use this grammar,
Or is there another way?

—————————————————————————————————————————-
?: (what is a _*1 >) keep() $$tmp = _0
  $$url = ^”\“https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exsentences=2&exintro;=&explaintext;=&format=json&titles;=$$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)
  ^jsontree($$tmp)
  ^jsonpath(  “.query .pages .56333 .extract” $$tmp)
  @0 = query(direct_v ? extract ? 1)
  @0object
——————————————————————————————————————————

 

 
  [ # 1 ]

If the website you use supports JSON data (most do) then you can use ^jsonopen (see JSON manual of ChatScript)

 

 
  [ # 2 ]

^jsonopen would give you a json as provided by the appropriate API. Then you can parse and use the relevant info out of that json. The above code is just parsing the resulting json to extract the needed data.
Also to the json help documentation in the documentation.

 

 
  login or register to react