Hi Nick,
Thank you for posting your question here.
Currently we do support making requests and generating single-choice questions on the fly. However, it is only achievable through editing our chat script at this moment. The screenshots you posted are from our config-doc. From the config-doc, we generates script, this is where we are going to make changes. (You can find some brief introduction of different files in IDE here: https://docs.juji.io/juji-ide/#code-editor) In general, we want to edit the latest web-* or facebook-* script depends on which channel you are using. And it is a good practice to save and download the script (or download the script and edit locally then do upload) so you will always have a copy, in case the script get overwritten. Editing the script file is a little bit involved, because our script are very powerful and flexible. Some coding experience may be handy.
Base on what I understand, what you want to accomplish takes two steps, 1) getting the data from API call and 2) generate a question dynamically.
Getting the data
You probably see something like this for your T1 topic in the script
(deftopic
handle-ask-how-are-you-doing_1
[?q]
{:default-rules
({:include-after
[(juji.topics.interviewing.v4/handle-how-are-you-doing-default
?q)]}
[]
["Thanks. We are looking into our system… "
(<-| topic_1_triggered-by “trigger-1”)
(record-answer ?q (input-text))]),
:include-after
[(juji.topics.interviewing.v4/handle-how-are-you-doing-main ?q)
(juji.topics.interviewing.v4/handle-interview-fallback ?q)],
:include-before [],
:pre-action [],
:post-action []})
Now you want to update the default-rules, more specifically replace the following part
[]
["Thanks. We are looking into our system… "
(<-| topic_1_triggered-by “trigger-1”)
(record-answer ?q (input-text))]
with another rule that captures user input, make a request and stores what you need in a variable. (Please refer to this page: https://docs.juji.io/concept/, for more details about topic and rules) The rule maybe something like the following
[+]
["Thanks. We are looking into our system… "
(record-answer ?q (input-text))
(<-| request-results (make-request “your-api-address” {:query-1 (input-text))]
You can refer to https://docs.juji.io/function/ for different functions used here (<-|
is also a function). And now, the data is stored in the variable request-results
Generate a dynamic single choice question
We do this by using make-single-choice-question
and the data we have from the API call. You probably have some topic similar to the one below in your script.
(deftopic
collect-basic-info-from-gui_4
[?q]
{:pre-condition [(and (= (>- topic_1_triggered-by) “trigger-1”))],
:pre-action [],
:post-action []}
[]
[(ask-question-gui ?q)]
(juji.topics.interviewing.v4/handle-gui-completion ?q))
What you need to change is to clear out the :pre-condition and update the rule. After the change, it would be something like this:
(deftopic
collect-basic-info-from-gui_4
[]
{:pre-condition [],
:pre-action [],
:post-action []}
[]
[(ask-question-gui (-<- dynamic-choice (make-single-choice-question “Is it one of the wine you are looking for ?” (format-my-data (>- request-results)))))]
(juji.topics.interviewing.v4/handle-gui-completion (>- dynamic-choice)))
Since what you get from the api call may not be the right format for the single-choice-question, you may need to format your data a bit. Here I created one of my own clojure function (refer to https://docs.juji.io/udf/#clojure-udf for more detail about user defined functions) format-my-data
for the job.
(defn map-indexed-fn
[ind datom]
[datom ind])
(defn format-my-data
[request-data]
(vec (map-indexed map-indexed-fn (vals (get-in (json/parse-string request-data) [“data” 0])))))
If your data is in json and you would like to use json/parse-string
, please make sure you include the namespace for the json package the the beginning of the script (e.g., abcd-1234567.eng00.lal.preview
).
You can download an example script with fake data: http://s000.tinyupload.com/index.php?file_id=00334504524239285737
You can upload this script and try the behavior buy using the Preview function in the IDE.
Hopefully this is helpful.
Best,
Wenxi