Table Chats

Automatic creation of table for messages

The following table is created to store all messages, both from the user (client) and from the bot, it can also store the messages that are sent in case a front-end is configured for possible interaction with the user.

By default these columns will be created in the table:

const columns = [
    {name: 'id', type: 'bigserial', primaryKey: true},
    {name: 'wa_id', type: 'text', notNull: true},
    {name: 'wam_id', type: 'text', notNull: true},
    {name: 'type', type: 'text', notNull: true},
    {name: 'outgoing', type: 'boolean', notNull: true},
    {name: 'body', type: 'text', notNull: true},
    {name: 'status', type: 'text',notNull: true},
    {name: 'caption', type: 'text', null: true},
    {name: 'data', type: 'bytea', notNull: true},
    {name: 'bot', type: 'boolean'},
    {name: 'created_at', type: 'timestamptz', notNull: true},
    {name: 'updated_at', type: 'timestamptz', notNull: true},
]

In the same way as with the bucket storage, it will also check if this table is already created, and in case it is not created, it will create it together with the corresponding rls policies for its correct functioning (you can configure the corresponding policies in supabase if you want or add them).

If you want to add a new policy you must do it here:

Be sure to make the database query asynchronous, otherwise it may fail, resulting in the database not being applied.

Última actualización