我想将我的对话流聊天机器人连接到这个API。这样,每当我写“古兰经在哪里谈论真主”时,它都会转到这个 api 并向https://islam360api.herokuapp.com/Allah发出 HTTP 获取请求并返回响应。
我已经在意图中打开了“Webhook”,并将 api 链接添加为对话流实现 url。但是如何教对话流在每个对https://islam360api.herokuapp.com的 api 调用之后连接单词“Allah”或用户可能说的任何其他内容,并发出 HTTP 获取请求并返回响应?我需要使用动作吗?做什么的?或者我是否需要使用内联编辑器,而不是实现下的“Webhook”?
编辑
应用程序.js
const sqlite3 = require('sqlite3').verbose();
const express = require("express");
// Notice that the execution mode is set to verbose to produce long stack traces.
var app = express();
var ayats=[];
app.get("/:find",function(request, response)
{
let db = new sqlite3.Database("./file.db",(err) => {
if (err){
console.log("Not connected to sqlite")
}
else{
console.log("Connected to sqlite")
}
});
// The sqlite3.Database() returns a Database object and opens the database connection automatically.
let sql = `SELECT SuratNameEng, AyatNo, English FROM surah`;
db.all(sql, [], (err, rows) => {
if (err) {
throw err;
}
rows.forEach((row) => {
ayats.push(JSON.stringify({Translation: row.English,SuratName: row.SuratNameEng,AyatNo: row.AyatNo}));
});
console.log(ayats);
ayats.forEach(function(element) {
if (element.toLowerCase().includes(request.params.find.toLowerCase())===true)
{
element=JSON.parse(element)
response.write(JSON.stringify({speech: "In"+ element.SuratName+", Ayat Number: "+element.AyatNo+", Quran says: "+ element.Translation, displayText: "In"+ element.SuratName+", Ayat Number: "+element.AyatNo+", Quran says: "+ element.Translation}))
}
});
response.send();
});
empty();
function empty() {
ayats.length = 0;
}
db.close((err) => {
if (err) {
return console.error(err.message);
}
console.log('Close the database connection.');
});
})
// It is a good practice to close a database connection when you are done with it.
var port = process.env.PORT || 3000;
app.listen(port,()=>console.log("Active"));