如何获得用户first_name在电报聊天机器人与dialogflow_es构建



我是Dialogflow的新手,想了解如何在我创建的Telegram聊天机器人中提取用户的first_name。我使用intent +内联编辑器(下面的代码)构建了一个聊天机器人,并学习了如何使用agent从响应中获取用户数据。参数,但仍然不能编写任何代码来提取部分用户的有效负载数据以在不请求它的情况下获得first_name。我使用了下面的代码,但它不起作用:

let display_name = agent.originalRequest.payload.data.message.from.first_name

如果有人能解释正确的代码函数来提取这些数据,我将不胜感激!完整的内联代码如下:

'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const admin = require ('firebase-admin');
admin.initializeApp();
admin.auth();
const db = admin.firestore();
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });

function welcome(agent) {
agent.add(`Hi! Do you want to create an account?`);
}

function createUser(agent) {
agent.add(`Thank you! You have successfully created your account`);
let uid = makeid(28);
let email = agent.parameters.email;
let password = agent.parameters.user_password;
let display_name = agent.parameters.display_name;
admin.auth().createUser({uid: uid, email: email, password: password});
db.collection('users').doc(uid).set(
{uid: uid, 
display_name: display_name, 
});
}

function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}

let intentMap = new Map();
intentMap.set('Welcome Intent', welcome);
intentMap.set('account.creation', createUser);
intentMap.set('Default Fallback Intent', fallback);
agent.handleRequest(intentMap);
});

这是为我工作的代码

let payload = agent.originalRequest;
let firstname = payload.payload.data.from.first_name;

相关内容

  • 没有找到相关文章

最新更新