In this article we will talk about the EDDI's http calls httpCalls feature.
The http calls feature httpCalls feature allows a chatbot to consume 3rd party APIs or even your own api APIs and use the JSON response in another http call or in EDDIanother httpCall (for authentication or requesting a token for instance) or directly print the results in chatbot's output; this means, for example, you can call a weather api and use the JSON response in your chatbot's output if the user asks about today's weather or the week's forecast!
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
{ "targetServer": "string", "httpCalls": [ { "name": "string", "saveResponse": true, "responseObjectName": "string", "actions": [ "string" ], "request": { "path": "string", "headers": {}, "queryParams": {}, "method": "string", "contentType": "string", "body": "string" }, "postResponse": { "qrBuildInstruction": { } ] } |
Description :
...
"pathToTargetArray": "String",
"iterationObjectName": "String",
"quickReplyValue": "String",
"quickReplyExpressions": "String"
}
}
}
]
} |
Description :
an http call is mainly composed from the targetServer array of httpCalls, the latter will have request where you put all details about your actual http request(method,path,headers, etc..) and postResponse
where you can define what happens after the httpCall has been executed and a response has been received; such as quick replies by using qrBuildInstruction
.
You can ${memory.current.httpCalls.<responseObjectName>} to access your JSON object, so you can use it in output templating or in another http call, for example an http call will get the oAuth token and another http call will use in the http headers to authenticate to an api.
targetServer | (String ) root/context path of the http call (e.g http://example.com/api) | ||
---|---|---|---|
httpCall.saveResponse | (Boolean ) whether to save the json response into ${memory.current.httpCalls} | ||
httpCall.responseObjectName | (String ) name of the json object so it can be accessed from other http calls or outputsets. | ||
httpCall.actions | (String ) name of the output/behavior set mapped to this http call. | ||
httpCall.request.path | (String ) path of the http call (e.g /books) | ||
httpCall.request.headers | (String: key,value ) for each http call header | ||
httpCall.request.queryParams | (String: key,value ) for each http call query parameter | ||
httpCall.request.method | (String ) Http method of the http call (e.g GET,POST,etc...) | ||
httpCall.request.contentType | (String ) value of the contentType header of the http call | ||
httpCall.request. | headersbody | (String | : key,value) for each http call header) an escaped JSON object that goes in the http request body if needed. |
httpCall.requestpostResponse.qrBuildInstruction.queryParamspathToTargetArray | (String : key,value) for each http call query parameter) path to the array in your JSON response data | ||
httpCall.requestpostResponse.qrBuildInstruction.methoditerationObjectName | (String ) Http method of the http calla variable name that will point to the TargetArray . | ||
httpCall.requestpostResponse.qrBuildInstruction.contentTypequickReplyValue | (String ) value of the contentType header of the http call | httpCall.request.body | (String) in escaped json value of the request body if applicablethymeleaf expression to use as a quick reply value. |
httpCall.postResponse.qrBuildInstruction.quickReplyExpressions | (String ) expression to retreive a property from iterationObjectName. |
The API endpoints :
HTTP Method | API Endpoint | Request Body | Response |
---|---|---|---|
DELETE | /httpcallsstore/httpcalls/{id} | N/A | N/A |
GET | /httpcallsstore/httpcalls/{id} | N/A | http-call-model |
PUT | /httpcallsstore/httpcalls/{id} | http-call-model | N/A |
GET | /httpcallsstore/httpcalls/descriptors | N/A | list of references to http-call-model |
POST | /httpcallsstore/httpcalls | http-call-model | N/A |
GET | /httpcallsstore/httpcalls/{id}/currentversion | N/A | http-call-model |
POST | /httpcallsstore/httpcalls/{id}/currentversion | http-call-model | N/A |
...
Step by step example :
We will do a step by step example from scratch (chatbot creation to a simple conversation that uses http call)
...