首页 > 解决方案 > Actions on Google 的登录方法存在问题

问题描述

我正在尝试为我的 AoG 使用谷歌登录方法,为我的用户提供更多定制体验,并将存储用户的一些数据以便我可以给出更相关的答案。我正在使用 dailogflow。调用登录后我得到这个错误

模拟器截图.

app.intent('Default Welcome Intent',(conv)=>{
 
  conv.ask(`HIIIIIIIIIIIIIIIIIIIIIIIIIII`);
 
});
app.intent('ask_for_sign_in', (conv) => {
  conv.ask(new SignIn(`to get sign in details`));
  
});

app.intent('ask_for_sign_in_confirmation', (conv, params, signin) => {
  if (signin.status !== 'OK') {
    return conv.ask('You need to sign in before using the app.');
  }
  const payload = conv.user.profile.payload
  
    conv.ask(`I got your account details, ${payload.name}. What do you want to do next?`)
  const access = conv.user.access.token;
  
  db.collection("user").doc(access).set({
    name:"name",
    name2 : conv.user.access.name,
  }).then(()=>{
            conv.close(`document successfully written`);
            return;
  }).catch((e)=>{
    conv.close(`error writing document ${e}`);
  })
  // possibly do something with access token
  return conv.ask('Great! Thanks for signing in.');
});

标签: node.jsfirebaseactions-on-google

解决方案


app.intent('Start Signin', conv => {
  conv.ask(`siging you in`);
  conv.ask(new SignIn('To get your account details'))
})
app.intent('Default Welcome Intent',(conv)=>{
  conv.ask(`hi`);
})
// Create a Dialogflow intent with the `actions_intent_SIGN_IN` event.
app.intent('Get Signin', (conv, params, signin) => {
  if (signin.status === 'OK') {
    const payload = conv.user.profile.payload
    const {email} = conv.user;
    conv.ask(`I got your account details, ${payload.name}.and ${email} What do you want to do next?`)
    db.collection(`user`).doc(email).set({
      name:"some name",
    }).then(()=>{
          conv.ask(`success`);
          return;
    }).catch((e)=>{
        conv.close(`unscess ${e}`);
    })
  } else {
    conv.ask(`I won't be able to save your data, but what do you want to do next?`)
  }
})

这段代码可以很好地工作,如果像我这样的人想要存储用户的数据,以便您可以在需要时提供相关信息,它也在模拟器上工作,别担心,不要忘记在 dailogflow 中添加 clientIDapp=dailogflow({debug:true,clientID:"your clientID"})并从谷歌模块上的操作中获取登录方法{dailogflow,signIn}=require("actions-on-google")..


推荐阅读