Kogno
Search…
⌃K

Models

Models are classes, They talk to the database, store and validate data.
As in Rails, Kogno uses the ActiveRecord library for this purpose, so the implementation and operation is the same. So you can check out the official Rails documentation if you want to read more about Models.

Creating a new Model

Model classes should be created in bot/models/ directory, where, in most cases, each one should have a corresponding database table. Which was previously configured.
In the example below, we will create Product model in bot/models/product.rb file.
For this to work, there must be a table in the database called products.
class Product < ActiveRecord::Base
end

Associations

All the models that are needed can be created (with exception of the predefined by Kogno), defining associations between them.
To lear more about associations you can read: A Guide to Active Record Associations.

Predefined models

In a new project, by default the following models and their corresponding tables are created:
User
users
Corresponds to users who are having or have had a conversation with the app.
Sequence
kogno_sequences
Message queue of the Sequences.
ChatLog
kogno_chat_logs
Stores log of incoming messages/events and replies, if enabled the project's configuration.
ScheduledMessage
kogno_scheduled_messages
LongPayload
kogno_long_payloads
It allows the creation of payloads with a number of characters greater than those delimited on each platform.
MatchedMessage
kogno_matched_messages
Used for updating messages feature from Telegram.
MessengerRecurringNotification
kogno_messenger_recurring_notifications
Stores the user's subscription current status from Messenger Recurring Notifications.
TelegramChatGroup
kogno_telegram_chat_group
Store the Telegram groups or channels where the bot has been included.
Last modified 8mo ago