Storing “Session Variables” in Facebook Messenger

2019-09-05 18:38发布

问题:

I want to save information about a user (ex postal code, location...) for the duration of the 'session', how could I go about this? From my understanding each time a message is sent, the webhook is hit again, so variables aren't saved on the webhook side. Furthermore, meta data is only available sending from bot to client. I'm looking for a way for the client to influence the flow without the use of a database.

Is this possible given the current iteration of the facebook messenger platform?

回答1:

There is no way to store variables in messenger.

If you really want to avoid persistence in your webhook code, you could use postabck buttons. The payload text limit is 1000 characters, which you could use to encode some limited data.

See https://developers.facebook.com/docs/messenger-platform/send-api-reference/postback-button

Personally I'm using firebase to handle this type of session storage and it's working well