# Models

As in Rails, Kogno uses the [`ActiveRecord`](https://www.rubydoc.info/gems/activerecord) library for this purpose, so the implementation and operation is the same.  So you can check out the official [Rails documentation](https://guides.rubyonrails.org/active_record_basics.html) 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](/getting-started.md#configure-the-database).

In the example below, we will create  <mark style="color:orange;">`Product`</mark> model in `bot/models/product.rb` file.

For this to work, there must be a table in the database called `products`.

```ruby
class Product < ActiveRecord::Base
end
```

{% hint style="success" %}

### Associations

All the models that are needed can be created (with exception of the predefined by Kogno), defining associations between them.&#x20;

To lear more about associations you can read: [A Guide to Active Record Associations](https://guides.rubyonrails.org/v3.2/association_basics.html)`.`
{% endhint %}

## Predefined models

In a new project, by default the following models and their corresponding tables are created:

<table data-header-hidden><thead><tr><th width="380.3614774524641">Model</th><th width="229.311377245509">Table</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:orange;"><code>User</code></mark></td><td><code>users</code></td><td>Corresponds to users who are having or have had a conversation with the app.</td></tr><tr><td><mark style="color:orange;"><code>Sequence</code></mark></td><td><code>kogno_sequences</code></td><td>Message queue of the <a href="/pages/EO0XvZsERaHFF8IvI7SU">Sequences</a>.</td></tr><tr><td><mark style="color:orange;"><code>ChatLog</code></mark></td><td><code>kogno_chat_logs</code></td><td>Stores log of incoming messages/events and replies, if enabled the <a href="/pages/-M1V7gvjf1yBDZ6db3GB">project's configuration</a>.</td></tr><tr><td><mark style="color:orange;"><code>ScheduledMessage</code></mark></td><td><code>kogno_scheduled_messages</code></td><td><a href="/pages/k9YNvkUnFbk3RhVFGBGP">Scheduled Messages </a>queue.</td></tr><tr><td><mark style="color:orange;"><code>LongPayload</code></mark></td><td><code>kogno_long_payloads</code></td><td>It allows the <a href="/pages/sK4FLcPtE5qFJRVSob6k#set_payload-payload-string-params-hash">creation of payloads</a> with a number of characters greater than those delimited on each platform.</td></tr><tr><td><mark style="color:orange;"><code>MatchedMessage</code></mark></td><td><code>kogno_matched_messages</code></td><td>Used for <a href="https://core.telegram.org/bots/api#updating-messages">updating messages</a> feature from Telegram.</td></tr><tr><td><mark style="color:orange;"><code>MessengerRecurringNotification</code></mark></td><td><code>kogno_messenger_recurring_notifications</code></td><td>Stores the user's subscription current status from <a href="/pages/dGQhmqxqmGo4fCT4H4dj">Messenger Recurring Notifications</a>.</td></tr><tr><td><mark style="color:orange;">TelegramChatGroup</mark></td><td><code>kogno_telegram_chat_group</code></td><td>Store the Telegram groups or channels where <a href="/pages/-M1XnHZ_rHA9okouJMhr">the bot has been included</a>.</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kogno.io/models.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
