[GH-ISSUE #1982] [FEAT]: API Access to Embed Chatbox #1286

Closed
opened 2026-02-22 18:24:06 -05:00 by yindo · 3 comments
Owner

Originally created by @QRMarketing on GitHub (Jul 27, 2024).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/1982

Originally assigned to: @shatfield4 on GitHub.

What would you like to see?

The Anything-llm API works well. However, I was wondering if there is a way to access the chat conversation messages from the embed chatboxes. This obviously would be extremely useful for any website chatbox implementation. Something like the following:

/v1/workspace/(workspace-slug)/embed-chat/chats : return in an array all the chat embed messages (with their respective data-embed-id) set up for that workspace.
/v1/workspace/(workspace-slug)/embed-chat/(data-embed-id)/chat : Execute a embed chat with a workspace

Or am I missing something and there is another way to access this data?

Note: just curious, I noticed no way to clear all the embed chats. So its stores them all forever?

Originally created by @QRMarketing on GitHub (Jul 27, 2024). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/1982 Originally assigned to: @shatfield4 on GitHub. ### What would you like to see? The Anything-llm API works well. However, I was wondering if there is a way to access the chat conversation messages from the embed chatboxes. This obviously would be extremely useful for any website chatbox implementation. Something like the following: /v1/workspace/(workspace-slug)/embed-chat/chats : return in an array all the chat embed messages (with their respective data-embed-id) set up for that workspace. /v1/workspace/(workspace-slug)/embed-chat/(data-embed-id)/chat : Execute a embed chat with a workspace Or am I missing something and there is another way to access this data? Note: just curious, I noticed no way to clear all the embed chats. So its stores them all forever?
yindo added the enhancementfeature request labels 2026-02-22 18:24:06 -05:00
yindo closed this issue 2026-02-22 18:24:06 -05:00
Author
Owner

@QRMarketing commented on GitHub (Jul 28, 2024):

This was a hack but it works - for ideas only for those in a pinch:

In: \server\utils\chats\embed.js


const { SendChatHistory} = require('./mf_chatEmbed'); // add a function at line 6
SendChatHistory(embed.workspace.slug, sessionId, message, completeText); // around line 182


Added file: \server\utils\chats\mf_chatEmbed.js who's contents has:


function SendChatHistory(workspaceSlug, sessionId, message, completeText) {
    const mysql = require('mysql2');
    const connection = mysql.createConnection({
        host: 'localhost',
        user: 'user',
        password: 'password',
        database: 'database',
    });
    connection.connect((err) => {
        if (err) {
            console.error('Error connecting to the database:', err.stack);
            return;
        }
        connection.execute(
            'SELECT * FROM chats WHERE chatsession = ? AND workspace = ?',
            [sessionId, workspaceSlug],
            (error, results, fields) => {
                if (error) {
                    console.error('Error executing query:', error.stack);
                    connection.end();
                    return;
                }
                if (results.length === 0) {
                    const summary = "";
                    const interest = "YES";
                    const chatstatus = "OPEN";
                    connection.execute(
                        'INSERT INTO chats (workspace, chatsession, summary, chatdate, interest, chatstatus) VALUES (?, ?, ?, NOW(), ?, ?)',
                        [workspaceSlug, sessionId, summary, interest, chatstatus],
                        (error, insertResults, fields) => {
                            if (error) {
                                console.error('Error executing insert query:', error.stack);
                                connection.end();
                                return;
                            }
                            const id_chats = insertResults.insertId;
                            connection.execute(
                                'INSERT INTO chathistory (id_chats, messageai, messageuser, messagedate) VALUES (?, ?, ?, NOW())',
                                [id_chats, message, completeText],
                                (error, results, fields) => {
                                    if (error) {
                                        console.error('Error executing insert query:', error.stack);
                                    }
                                    connection.end();
                                }
                            );
                        }
                    );
                } else {
                    const id_chats = results[0].id;
                    connection.execute(
                        'INSERT INTO chathistory (id_chats, messageai, messageuser, messagedate) VALUES (?, ?, ?, NOW())',
                        [id_chats, message, completeText],
                        (error, results, fields) => {
                            if (error) {
                                console.error('Error executing insert query:', error.stack);
                            }
                            connection.end();
                        }
                    );
                }
            }
        );
    });
}
module.exports = {
    SendChatHistory,

};

Database:


CREATE DATABASE IF NOT EXISTS `mydatabase` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
USE `mydatabase`;

CREATE TABLE IF NOT EXISTS `chathistory` (
  `id` int NOT NULL AUTO_INCREMENT,
  `id_chats` int DEFAULT NULL,
  `messageai` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
  `messageuser` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
  `messagedate` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `chats` (
  `id` int NOT NULL AUTO_INCREMENT,
  `workspace` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `chatsession` varchar(50) DEFAULT NULL,
  `summary` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci,
  `chatdate` datetime DEFAULT NULL,
  `interest` varchar(50) DEFAULT NULL,
  `chatstatus` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `systemconfiguration` (
  `id` int NOT NULL AUTO_INCREMENT,
  `workspace` varchar(50) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

CREATE TABLE IF NOT EXISTS `workspaceconfiguration` (
  `id` int NOT NULL AUTO_INCREMENT,
  `id_systemconfiguration` int DEFAULT NULL,
  `host` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

@QRMarketing commented on GitHub (Jul 28, 2024): This was a hack but it works - for ideas only for those in a pinch: In: \server\utils\chats\embed.js ``` const { SendChatHistory} = require('./mf_chatEmbed'); // add a function at line 6 SendChatHistory(embed.workspace.slug, sessionId, message, completeText); // around line 182 ``` Added file: \server\utils\chats\mf_chatEmbed.js who's contents has: ``` function SendChatHistory(workspaceSlug, sessionId, message, completeText) { const mysql = require('mysql2'); const connection = mysql.createConnection({ host: 'localhost', user: 'user', password: 'password', database: 'database', }); connection.connect((err) => { if (err) { console.error('Error connecting to the database:', err.stack); return; } connection.execute( 'SELECT * FROM chats WHERE chatsession = ? AND workspace = ?', [sessionId, workspaceSlug], (error, results, fields) => { if (error) { console.error('Error executing query:', error.stack); connection.end(); return; } if (results.length === 0) { const summary = ""; const interest = "YES"; const chatstatus = "OPEN"; connection.execute( 'INSERT INTO chats (workspace, chatsession, summary, chatdate, interest, chatstatus) VALUES (?, ?, ?, NOW(), ?, ?)', [workspaceSlug, sessionId, summary, interest, chatstatus], (error, insertResults, fields) => { if (error) { console.error('Error executing insert query:', error.stack); connection.end(); return; } const id_chats = insertResults.insertId; connection.execute( 'INSERT INTO chathistory (id_chats, messageai, messageuser, messagedate) VALUES (?, ?, ?, NOW())', [id_chats, message, completeText], (error, results, fields) => { if (error) { console.error('Error executing insert query:', error.stack); } connection.end(); } ); } ); } else { const id_chats = results[0].id; connection.execute( 'INSERT INTO chathistory (id_chats, messageai, messageuser, messagedate) VALUES (?, ?, ?, NOW())', [id_chats, message, completeText], (error, results, fields) => { if (error) { console.error('Error executing insert query:', error.stack); } connection.end(); } ); } } ); }); } module.exports = { SendChatHistory, }; ``` Database: ``` CREATE DATABASE IF NOT EXISTS `mydatabase` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */; USE `mydatabase`; CREATE TABLE IF NOT EXISTS `chathistory` ( `id` int NOT NULL AUTO_INCREMENT, `id_chats` int DEFAULT NULL, `messageai` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, `messageuser` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, `messagedate` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; CREATE TABLE IF NOT EXISTS `chats` ( `id` int NOT NULL AUTO_INCREMENT, `workspace` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL, `chatsession` varchar(50) DEFAULT NULL, `summary` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci, `chatdate` datetime DEFAULT NULL, `interest` varchar(50) DEFAULT NULL, `chatstatus` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; CREATE TABLE IF NOT EXISTS `systemconfiguration` ( `id` int NOT NULL AUTO_INCREMENT, `workspace` varchar(50) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; CREATE TABLE IF NOT EXISTS `workspaceconfiguration` ( `id` int NOT NULL AUTO_INCREMENT, `id_systemconfiguration` int DEFAULT NULL, `host` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; ```
Author
Owner

@timothycarambat commented on GitHub (Jul 28, 2024):

All of the session chat data is available from [URL]/settings/embed-chats for review, but yes there is no current API access endpoint.

Which would need:

  • All chats
  • Chats by sessionID

@QRMarketing Can i ask why you need to send a chat for an embed though? I dont see the use-case in that aspect so clearly.

@timothycarambat commented on GitHub (Jul 28, 2024): All of the session chat data is available from `[URL]/settings/embed-chats` for review, but yes there is no current API access endpoint. Which would need: - All chats - Chats by sessionID @QRMarketing Can i ask why you need to send a chat _for an embed_ though? I dont see the use-case in that aspect so clearly.
Author
Owner

@QRMarketing commented on GitHub (Jul 29, 2024):

One really good use case for an AI chatboxes is on websites for sales/lead generation. The current chatbox is reactive in the sense; you pose questions - it responds. A sales chatbox should be proactive and pose questions to the user not wait for a question. Like what is your name, what is your contact details, did you know we have this? ... etc.

I tried to use documents to educate the AI with rules - like: After 2 chat questions, ask the user for their name ... then their email. This had limited success and I had to remind all the time the AI about their rules. It reluctantly did it, but not good for production environment. Perhaps I need to find out better how to train it to obey its rules.

@QRMarketing commented on GitHub (Jul 29, 2024): One really good use case for an AI chatboxes is on websites for sales/lead generation. The current chatbox is reactive in the sense; you pose questions - it responds. A sales chatbox should be proactive and pose questions to the user not wait for a question. Like what is your name, what is your contact details, did you know we have this? ... etc. I tried to use documents to educate the AI with rules - like: After 2 chat questions, ask the user for their name ... then their email. This had limited success and I had to remind all the time the AI about their rules. It reluctantly did it, but not good for production environment. Perhaps I need to find out better how to train it to obey its rules.
yindo changed title from [FEAT]: API Access to Embed Chatbox to [GH-ISSUE #1982] [FEAT]: API Access to Embed Chatbox 2026-06-05 14:39:57 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#1286