简体   繁体   中英

How to map storage.userId and idToken in Google Assistant actionSdk

  1. Hi, We have created a bot where user interact with the bot. so our bot has two type of queries static and dynamic queries. if user asks static query we don't ask for SIGN IN but if user ask for dynamic query than we ask user to SIGN IN and redirect to SIGN IN page than we ask mobile no and dob and send OTP to user and than verify the user and send back a token in response which we get in further request. The problem is let use suppose user came on our our bot and asked static query so i store the chat of user to my db initially I create a userId for user like this conv.user.storage.userId = 'unique_id' and store this unique_id in my db to identify the user next time and send back. Next time same bot get same userId and keep updating my chat in db for this userId. Now the problem comes when users asks a dynamic query than I have to redirect user to our account linking page. user is redirectd to account linking page and user fill his mobile no. and DOb and we send a otp to usermobile. When our SendOtp api is called I create a userId and store in databse but I want the userId which I set before for static queries (conv.user.storeage.userId) this one. How can I get this Id. Can we pass this userId as params to when to ask for SIGN In (conv.ask(new SignIn('To get your account details'))) and get this static query userId in my SendOtp API. I need same ID to send further to update chat.

When you create a SignIn request, you cannot provide any additional data in that request. However, you are able to provide this behavior when your Action gets a callback. You will get aSign In event that can be set to when the user signs in. At that point you can add your additional logic to connect the user's account on your backend with the account ID in userStorage.

Here's an example of what it may look like.

app.handle('linkAccount', async conv => {
  let payload = conv.headers.authorization;
  if (payload) {
    // Perform account merge
    await performAccountMerge(payload.email, conv.user.storage.userId)
  }
});

async function performAccountMerge(authorizedEmail, savedUserId) {
  await saveInDatabaseForEmail(authorizedEmail, savedUserId)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM