ChatGPT 4-omni (ProTalk) + WordPress + Notion

In this case, we will show how to make a seller of goods or services in a Telegram bot directly from your WordPress site and collect orders in a convenient database in Notion

Step #1: Preparing WordPress

Let's prepare your WordPress site so that our bot can receive products in the required categories. To do this, add the following code to the `functions.php` file in your theme settings:

add_action('rest_api_init', function () {
    register_rest_route('myshop/v1', '/products', array(
        'methods' => 'GET',
        'callback' => 'get_products_info',
        'permission_callback' => '__return_true'
    ));
});
function get_products_info($request) {
    $category = $request->get_param('category');
    $args = array(
        'status' => 'publish',
        'limit' => -1
    );
    if ($category) {
        $args['category'] = array($category);
    }
    $products = wc_get_products($args);
    $data = array();
    foreach ($products as $product) {
        $data[] = array(
            'id' => $product->get_id(),
            'name' => $product->get_name(),
            'price' => $product->get_price(),
            'regular_price' => $product->get_regular_price(),
            'sale_price' => $product->get_sale_price(),
            'stock_status' => $product->get_stock_status(),
            'stock_quantity' => $product->get_stock_quantity(),
            'categories' => wp_list_pluck($product->get_category_ids(), 'name'),
            'permalink' => get_permalink($product->get_id()),
            'image_url' => wp_get_attachment_url($product->get_image_id()),
        );
    }
    return new WP_REST_Response($data, 200);
}
Example of installing a script for third-party requests to the product catalog

Example of installing a script for third-party requests to the product catalog

If you want to make sure that no one except the bot can access the site, you can add a password check, like this:

add_action('rest_api_init', function () {
    register_rest_route('myshop/v1', '/products', array(
        'methods' => 'GET',
        'callback' => 'get_products_info',
        'permission_callback' => 'check_api_password'
    ));
});

function check_api_password($request) {
    $api_password = 'your_secure_password_here'; // Замените на ваш пароль
    $provided_password = $request->get_param('api_password');

    if ($provided_password && $provided_password === $api_password) {
        return true;
    } else {
        return new WP_Error('rest_forbidden', 'Неверный пароль API', array('status' => 401));
    }
}

function get_products_info($request) {
    $category = $request->get_param('category');
    $args = array(
        'status' => 'publish',
        'limit' => -1
    );
    if ($category) {
        $args['category'] = array($category);
    }
    $products = wc_get_products($args);
    $data = array();
    foreach ($products as $product) {
        $data[] = array(
            'id' => $product->get_id(),
            'name' => $product->get_name(),
            'price' => $product->get_price(),
            'regular_price' => $product->get_regular_price(),
            'sale_price' => $product->get_sale_price(),
            'stock_status' => $product->get_stock_status(),
            'stock_quantity' => $product->get_stock_quantity(),
            'categories' => wp_list_pluck($product->get_category_ids(), 'name'),
            'permalink' => get_permalink($product->get_id()),
            'image_url' => wp_get_attachment_url($product->get_image_id()),
        );
    }
    return new WP_REST_Response($data, 200);
}

Step #2: Preparing Notion

There are a lot of videos on YouTube about working in Notion, even in Russian, so I'll give you a link to the one I received. sample for our bot in Notion.

Workspace for AI bot for sales from WordPress site

Workspace for AI bot for sales from WordPress site

Step #3: Creating a Telegram Bot on the ProTalk Platform

Here is a link to a guide on creating a Telegram bot on the ProTalk platform:

And the final role of the bot:

Ты - опытная и дружелюбная менеджер по продаже светильников. Твоя цель - обеспечить клиентов качественными консультациями и помочь им сделать правильный выбор.

Твоя задача - помочь клиентам выбрать подходящие светильники на сайте [https://svetaluks.ru](https://svetaluks.ru/) и успешно завершить продажу.

Когда клиент определится с выбором ты должна спросить его имя и номер телефона, после чего отправить эти данные в таблицу Notion: [https://www.notion.so/0b27ddc833864c558376d2537ea11ddf?v=b7c69c8af2294ae8857c04bc86f6b86d&pvs=4](https://www.notion.so/0b27ddc833864c558376d2537ea11ddf?pvs=21)

Поля для записи заявки:

```markdown
“Клиент” - это заголовок, сюда запиши имя клиента
“Телефон” - текстовое поле, сюда запиши телефон клиента
“Заказ” - тектовое поле, сюда запиши заказ клиента
"Сумма" - числовое поле, сюда запиши сумму заказа
```

Используй эти категории для поиска светильников:
"childrens-table-lamps" - детские настольные светильники.

Токен для записи в Notion : “secret_EPGE2uRL85XXXXXXXXXXXXXXXXXXXXXXXXX”

Не выходи из своей роли.

By the way, we also moved the role itself to Notion, like this:

Using a Notion Page as an External Role for a Bot on the ProTalk Platform

Using a Notion Page as an External Role for a Bot on the ProTalk Platform

As a result, we get a bot like this:

Bot on ProTalk platform

Bot on ProTalk platform

We have connected two functions to the bot:

Connected functions to the bot on ProTalk

Connected functions to the bot on ProTalk

Function for connecting with a WordPress site

Function for connecting with a WordPress site

Function for writing to a Notion table

Function for writing to a Notion table

Step #4: Test the Bot

The bot uses a connection to a WordPress site and offers us products

The bot uses a connection to a WordPress site and offers us products

The bot sends the order to the Notion database

The bot sends the order to the Notion database

The order is created correctly and everything is distributed to the required columns.

The order is created correctly and everything is distributed to the required columns.

Additionally, we can enable the following settings for the bot:

Dialogue settings in ProTalk bots

Dialogue settings in ProTalk bots

A feature that will allow the bot to resume the current dialogue after a few days, at a time convenient for the client

A feature that will allow the bot to resume the current dialogue after a few days, at a time convenient for the client

And then the following behavior of the bot will become possible:

AI bot ProTalk can resume dialogue at a time convenient for the client

AI bot ProTalk can resume dialogue at a time convenient for the client

Results

Based on the given case, the idea of ​​”packaging” AI companies ready for replication in the form of a Notion template arises, which will contain:

  1. Roles of all AI employees

  2. Knowledge Bases in Notion Tables

  3. Databases of applications (leads) from bots

If you have any other ideas on how to use the AI ​​bots bundle with Notion, write about them in the comments or to me at Telegram.

P.S. Video on creating a bot from this article

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *