npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@voscarmv/aichatbot

v1.0.17

Published

AI chatbot framework for messaging apps

Readme

aichatbot

AI chatbot framework for messaging apps. Supports concurrent messages through queueing, as well as AI tool calls.

Telegram bot example

Demo here.

Using

npm install @voscarmv/aichatbot @voscarmv/aimessagestore grammy axios dotenv
npm install -D typescript @types/node

index.ts

import { aiClient } from "./bot.js";
import { messageStore } from "./api.js";
import { ChatService } from "@voscarmv/aichatbot";
import { Bot } from "grammy";
import { operatingSystem } from "./utils/os.js";
import "dotenv/config";

const chat = new ChatService({
    aiClient,
    messageStore
});
if (!process.env.TELEGRAM_KEY) {
    throw new Error("TELEGRAM_KEY is not defined");
}
const bot = new Bot(process.env.TELEGRAM_KEY);

bot.on("message:text", async (ctx) => {
    const user_id = ctx.message.from.id.toString();
    const content = ctx.message.text;
    console.log(new Date(), "from:", user_id, content);
    const replyFn = (content: string) => {
        if(content.length === 0) return;
        console.log(new Date(), "to:", user_id, content);
        ctx.reply(content);
    }
    chat.processMessages({
        user_id, content, replyFn,
        additionalToolsArgs: operatingSystem,
        additionalInstructionsArgs: { date: new Date()}
    });
});

bot.start();

bot.ts

import { OpenAiClient } from "@voscarmv/aichatbot";
import "dotenv/config";
import { functions, tools } from "./tools.js";
import { currentDate } from "./utils/instructions.js";
if (!process.env.DEEPSEEK_KEY) {
    throw new Error("DEEPSEEK_KEY is not defined");
}
export const aiClient = new OpenAiClient({
    baseURL: 'https://api.deepseek.com',
    apiKey: process.env.DEEPSEEK_KEY,
    model: 'deepseek-chat',
    instructions: 'You are a helpful assistant.',
    tools,
    functions,
    additionalInstructions: currentDate
});

api.ts

import 'dotenv/config';
import { FunctionMessageStore } from '@voscarmv/aichatbot';
import axios from 'axios';

if (!process.env.MESSAGESTORE_URL) {
    throw new Error("MESSAGESTORE_URL is not defined");
}
const url = process.env.MESSAGESTORE_URL;

async function readUserMessages(user_id: string): Promise<string[]> {
    return (await axios.get<string[]>(`${url}/messages/${user_id}`)).data;
}

async function unqueueUserMessages(user_id: string): Promise<string[]> {
    return (await axios.put<string[]>(`${url}/messages/${user_id}/unqueue`)).data;
}

async function insertMessages(user_id: string, queued: boolean, msgs: string[]): Promise<string[]> {
    return (await axios.post<string[]>( `${url}/messages`, {user_id, queued, msgs})).data;
}

async function queuedMessages(user_id: string): Promise<string[]> {
    return (await axios.get<string[]>(`${url}/messages/${user_id}/queued`)).data;
}

export const messageStore = new FunctionMessageStore({
    readUserMessages,
    unqueueUserMessages,
    insertMessages,
    queuedMessages
});

server.ts

import { AiMessageStoreBackend } from "@voscarmv/aimessagestore";
import 'dotenv/config';

if (!process.env.DATABASE_URL) {
    throw Error('DATABASE_URL undefined');
}

const server = new AiMessageStoreBackend({
    dbUrl: process.env.DATABASE_URL,
    port: 3000
});

(async () => {
    console.log("Migrate DB");
    await server.migrate()
    console.log("Done Migrating DB. Start server...");
    server.listen();
})();

tools.ts

export const tools = [
    {
        type: 'function' as const,
        function: {
            name: 'getLang',
            description: 'Get the language for a given language code',
            parameters: {
                type: 'object',
                properties: {
                    language: {
                        type: 'string',
                        enum: ['en-US', 'es-MX'],
                        description: 'The language code',
                    }
                },
                required: ['language']
            }
        }
    },
    {
        type: 'function' as const,
        function: {
            name: 'throwDice',
            description: 'Throw N dice and get the results',
            parameters: {
                type: 'object',
                properties: {
                    nDice: {
                        type: 'integer',
                        description: 'Number N of dice to throw'
                    }
                },
                required: ['nDice']
            }
        }
    },
    {
        type: 'function' as const,
        function: {
            name: 'getOS',
            description: 'Return the host Operating System',
        }
    },
];

export const functions = {
    getLang: async (params: any, additionalArgs: any): Promise<string> => {
        const { language } = params;
        const langs: Record<string,string> = {
            'es-MX': 'Mexican Spanish',
            'en-US': 'US English'
        };
        return langs[language] || '';
    },
    throwDice: async (params: any, additionalArgs: any): Promise<string> => {
        const { nDice } = params;
        let result = [];
        function sleep(ms: number) {
            return new Promise(resolve => setTimeout(resolve, ms));
        }
        await sleep(5000);
        for (let i = 0; i < nDice; i++) {
            result.push(Math.floor(Math.random() * 6) + 1);
        }
        return JSON.stringify(result);
    },
    getOS: async (params: any, additionalArgs: any): Promise<string> => {
        const { platform, type, release, version } = additionalArgs;
        return `Platform: ${platform}, Type: ${type}, Release: ${release}, Version: ${version}`;
    },
};

utils/os.ts

import * as os from 'os';

const platform = os.platform();
const type = os.type();
const release = os.release();
const version = os.version();

export const operatingSystem: object = { platform, type, release, version };

utils/instructions.ts

export async function currentDate(args: object): Promise<string>{
    const { date } = args as { date: Date };
    return `Today is ${date.toString()}`;
}

About api.ts

You can use a different backend for messageStore() in api.ts.

Just follow the same storage and retrieval logic from @voscarmv/aimessagestore.