我正在使用Dialogflow和actions-on-google-nodejs
为Google助手创建一个操作,该操作可以访问GitKraken Glo API来将名片添加到用户板上。我正在使用帐户链接对用户进行身份验证。我希望我的用户能够说诸如Add a card to [board name]
或Add a card
之类的内容。如果未提供板名,我希望该操作提示用户输入。如何创建一个会话实体,以获取已登录用户的所有面板名称?
很抱歉,如果这没有什么意义,我对Actions on Google和Dialogflow。随时提出问题以求清楚。
答案 0 :(得分:1)
您可以使用conv.user对象:
const Users = {};
app.intent('Get Signin', (conv, params, signin) => {
if (signin.status === 'OK') {
const email = conv.user.email
Users[email] = { };
conv.ask(`I got your email as ${email}. What do you want to do next?`)
} else {
conv.ask(`I won't be able to save your data, but what do you want to next?`)
}
})
app.intent('actions.intent.TEXT', (conv, input) => {
if (signin.status === 'OK') {
Users[conv.user.email] = {
lastinput: input
};
}
});
具有转换ID的也是当前会话的唯一ID。
// Create an app instance
const app = dialogflow()
// Register handlers for Dialogflow intents
const Users = {};
app.intent('Default Welcome Intent', conv => {
Users[conv.id] = {
conversationId: conv.id,
name: '1234'
};
})
app.intent('actions.intent.TEXT', (conv, input) => {
Users[conv.id] = {
lastinput: input
};
});
app.intent('Goodbye', conv => {
delete Users[conv.id];
})
答案 1 :(得分:1)
要使用会话实体,首先需要做一些事情:
通常,您的代码需要执行以下操作,通常是在用户首次启动会话时(即-在“欢迎意图处理程序”中):
该库的自述文件包含指向有关如何使用nodejs库执行此操作的示例代码的链接。我执行此工作的代码具有如下功能:
function setSessionEntity( env, entityType ){
const config = envToConfig( env );
const client = new dialogflow.SessionEntityTypesClient( config );
let parent = env.dialogflow.parent;
if( entityType.displayName && !entityType.name ){
entityType.name = `${parent}/entityTypes/${entityType.displayName}`;
}
if( !entityType.entityOverrideMode ){
entityType.entityOverrideMode = 'ENTITY_OVERRIDE_MODE_OVERRIDE';
}
const request = {
parent: parent,
sessionEntityType: entityType
};
return client.createSessionEntityType( request );
}