【发布时间】:2020-08-25 11:48:59
【问题描述】:
我已经构建了一个带有电报集成的对话流聊天机器人,我需要获取用户在电报聊天中发送的图像的路径。据我所知,对话流机器人不听图像,所以我使用电报机器人对象来轮询消息以获取图像,但这样对话流机器人停止响应,即使在电报机器人的轮询停止后也是如此。两个机器人之间存在一些冲突。 “恢复”对话流机器人的唯一方法是在对话流 UI 中手动重新启动电报集成。 有一种方法可以解决两个机器人之间的冲突,以便在电报机器人获得图像后对话流机器人继续响应? 这是我写的代码:
const TG = require('node-telegram-bot-api');
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
function takeImagePath() {
agent.add(`send an image/photo`); // work
const token = 'my telegram bot token';
let telegramBot = new TG(token, {polling: true});
agent.add(`tg bot created`); // work
telegramBot.on('message', async function (msg) {
const chatId = msg.chat.id;
agent.add('bot dialogflow in the listener'); // don't work
if (msg.photo) {
let ImgID = msg.photo[msg.photo.length - 1].file_id;
let imgPath = "";
if (ImgID) {
telegramBot.getFile(ImgID).then((fileObject) => {
imgPath = fileObject.file_path;
}).then(() => telegramBot.sendMessage(chatId, 'image taken')) //work
.catch(error => console.log("error: " + error.message));
}
}
else { await telegramBot.sendMessage(chatId, "it's not an image, telegram bot shutting down"); //work
await telegramBot.stopPolling();
agent.add("bot dialogflow active"); // don't work
}
});
}
let intentMap = new Map();
intentMap.set('Image intent', takeImagePath);
agent.handleRequest(intentMap);
});
【问题讨论】:
标签: node.js telegram-bot dialogflow-es-fulfillment