webhooksgoogle-assistant-sdkactions-builder

How can I add user info to conv.user.storage?


I'm using Actions Builder to create my chatbot and after user logins using Google I want to save his ID to storage variable. This storage variable doesn't exist on conv.user. So I do this:

if (conv.user.verificationStatus === 'VERIFIED') {
  conv.user.storage = {};
  conv.user.storage.id = str.rows[0].id;
  console.log("STORAGE");
  console.log(conv.user.storage.id);
}

But on Google Assistant it returns the error message and on my Webhook it's all good (no errors shown): Google Assistant Error

What can I do to save/persist at least my user ID for future referings?


Solution

  • Since user has the Google Sign In process done once, every time he enters in your action you have his info on the request (payload). It´s automatically added to user storage.

    You should store it on conv.user.params and refer to it in your code.

    You may have a get and set method to help you with:

    getUserId(conv) {
        return conv.user.params.userId;
    }
    
    setUserId(conv, userId) {
        try {
            conv.user.params.userId = userId;
        } catch (e) {
            throw new error("Error setting USERID");
        }
    
        return userId;
    }