User model
It is one of the models that is predefined in a new project and is associated with the users table in the database.
In the conversation flow @user
can be called, which is an instance of this model for the user who is chatting.
Location
users
table schema
users
table schema
| Secuencial record ID. |
| The user identification on each platform. |
| The platform through which the user is chatting. |
| The user's ID who has commented on a post on the Fan Page associated with the project. |
| Facebook Page's ID |
| User's name. |
| User's first name. |
| User's last name. |
| User's timezone. |
| User's locale. |
| Stores the last time when a message or event was received from the user. |
| The current context of the conversation with the user. |
| Stores the parameters from the current context of the conversation with the user. |
| Stores the user's session vars. |
| Boolean that indicates if the last message sent was read by the user. |
| Date and time of record creation. |
| Date and time of the record's last update. |
Common Methods and Attributes.
first_time?()
first_time?()
This method returns true if the user has been created current session.
Usage
platform
platform
This attribute returns the user's platform. For example: "messenger"
, "telegram"
or "whatsapp"
.
Usage
context
context
Returns the current context of the conversation with the user.
Usage
exit_context()
exit_context()
Exit the user from the current context of the conversation.
Usage
reschedule_message(tag=Symbol, send_at=Time)
reschedule_message(tag=Symbol, send_at=Time)
Re-Schedule the messages associated with the provided tag.
Usage
scheduled_message?(tag=Symbol)
scheduled_message?(tag=Symbol)
Returns true if there is a scheduled message associated with the provided tag.
Usage
destroy_scheduled_messages(tag=Symbol)
destroy_scheduled_messages(tag=Symbol)
Deletes the scheduled message associated with the provided tag.
Usage
messenger_recurring_notification_data()
messenger_recurring_notification_data()
Returns the user's subscription status for Messenger Recurring Notifications
Usage
messenger_recurring_notification?()
messenger_recurring_notification?()
Returns true if the subscription to Messenger Recurring Notifications is active.
Usage
vars
vars
This attribute allows saving and retrieving any data within the conversation flow.
Saving data
Retrieving data
Deleting data
Para usar este attributo fuera del flujo de la conversación se necesita llamar a los metodos get_session_vars() y save_session_vars()
set_locale(locale=Symbol)
set_locale(locale=Symbol)
Set user locale
Usage
Customization Example
Suppose we need to ask the user to leave us their email and we would like to save that information.
To do this we could do the following:
Adding email field in users table.
Editing User model
In the User model we will create the methods that we consider necessary to carry out this operation: in this case we will create one to save the mail and another to verify that it exists.
Testing
We can test this on the console by running kogno c
in the terminal
Last updated