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

convex-chat-sdk

v0.1.0

Published

A Convex component and state adapter for Chat SDK.

Readme

Convex Chat SDK

npm version

Use Chat SDK bots with Convex. This package provides a Convex component plus a state adapter that wires Chat SDK state into Convex.

Installation

Install the component, Chat SDK itself, and the adapter you want to use in your Convex app:

npm install convex-chat-sdk chat @chat-adapter/telegram

Or with Bun:

bun add convex-chat-sdk chat @chat-adapter/telegram

Usage Guide

The basic setup has three parts:

  1. Install the Convex component in convex/convex.config.ts.
  2. Create a bot in convex/bot.ts.
  3. Register adapter-specific webhook routes in convex/http.ts.

1. Install the component

// convex/convex.config.ts
import { defineApp } from "convex/server";
import chatSdk from "convex-chat-sdk/convex.config.js";

const app = defineApp();
app.use(chatSdk);

export default app;

This exposes the component as components.chatSdk in your generated Convex API.

2. Create a bot

Build your bot from an action or HTTP action context with new Chat(...) and plug the Convex state adapter directly into the config.

// convex/bot.ts
import { createTelegramAdapter } from "@chat-adapter/telegram";
import { Chat } from "chat";
import { createConvexState } from "convex-chat-sdk";
import { components } from "./_generated/api";
import type { ActionCtx } from "./_generated/server";

export const createBot = (ctx: ActionCtx) => {
  const bot = new Chat({
    state: createConvexState(components.chatSdk, ctx),
    userName: "convex-bot",
    adapters: {
      telegram: createTelegramAdapter(),
    },
  });

  bot.onNewMessage(/.+/s, async (thread, message) => {
    await thread.post(`You said: ${message.text}`);
  });

  return bot;
};

createConvexState(...) creates a Convex-backed Chat SDK state adapter. Subscription state, locks, and key-value state are stored through the component.

3. Register webhook routes

Register the webhook route directly in convex/http.ts:

// convex/http.ts
import { httpRouter } from "convex/server";
import { httpAction } from "./_generated/server";
import { createBot } from "./bot";

const http = httpRouter();

http.route({
  path: "/webhooks/telegram",
  method: "POST",
  handler: httpAction(async (ctx, request) => {
    const bot = createBot(ctx);
    return bot.webhooks.telegram(request);
  }),
});

export default http;

Writing Handlers

Once you have a bot instance, you can use the usual Chat SDK handler APIs, for example:

bot.onNewMessage(/.+/s, async (thread, message) => {
  await thread.post(`You said: ${message.text}`);
});

Useful Chat SDK docs:

  • https://www.chat-sdk.dev/docs/usage
  • https://www.chat-sdk.dev/docs/posting-messages
  • https://www.chat-sdk.dev/docs/adapters

API

createConvexState(component, ctx)

Creates a Convex-backed Chat SDK state adapter.

  • component: usually components.chatSdk
  • ctx: a Convex action or HTTP action context
  • returns: a Chat SDK state adapter

Notes

  • This package is built on Chat SDK, so adapter behavior and message formats are defined by Chat SDK itself.
  • Follow the relevant Chat SDK adapter docs and validate them in your own environment.

Found a bug? File an issue.