User Attribute

We have the capability to assign attributes to a user as they chat with a bot. This is useful to store information about the user. For example, if we want to store the user's email, or if we want to store the user's favourite flavor of ice cream.

Let's go to the "you just said hello" story change the first text response to

text: What is your favorite flavor of ice cream?

then let's add a memory response

type: memory
property: asked-fav-icecream
function: $enable

Now the chat flows as follows:

User: hello there
Bot: hey!
Bot: (secretly, without telling the user, assigns *said-hey* to the chat)
User: how are you?
Bot: (saw that the property said-hey exists in the user's chat session)
Bot: What is your favorite flavor of ice cream?

Now let's add a NEW rule with a NEW condition

type: memory
property: asked-fav-icecream
function: $exists

and let's assign this to a new story called "entered fav ice cream"

Go to the "entered fav ice cream" story and add a new action response

type: user attribute
property: fav_ice_cream
function: $set_to_message

then add yet another text response

message: I love {{user.fav_ice_cream}} too! It's amazing.

We just used a merge tag called fav_ice_cream to refer to the new user attribute. Now the chat flows as follows:

User: hello there
Bot: hey!
Bot: (secretly, without telling the user, assigns *said-hey* to the chat)
User: how are you?
Bot: (saw that the property said-hey exists in the user's chat session)
Bot: What is your favorite flavor of ice cream?
Bot: (secretly, without telling the user, assigns *asked-fav-icecream* to the chat)
User: chocolate
Bot: (saw that the property asked-fav-icecream exists in the user's chat session)
Bot: (store's the user's last message to an attribute called fav_ice_cream)
Bot: I love chocolate too! It's amazing.

Now, refer to the user's favorite ice cream with the merge tag {{user.fav_ice_cream}} in any of our responses or cards REGARDLESS of the chat session.

The user will start chatting with the bot again tomorrow (theirfav_ice_cream will still be chocolate).

Last updated