> This page location: Functions > Templates > Chat SDK bot for Slack, Telegram, and the web
> Full Neon documentation index: https://neon.com/docs/llms.txt

# Chat SDK bot for Slack, Telegram, and the web

A Vercel Chat SDK bot that answers on Slack, Telegram, and useChat, streams replies from AI Gateway, and keeps conversations, subscriptions, and locks in Neon Postgres.

- First Party: maintained by Neon
- Built by: Neon
- Categories: First Party, Bots, AI

## Install

```bash
neon functions new chat-sdk
```

With the Neon CLI 8.11.0 or later, this command copies the template into `functions/<slug>/` and declares the function in `neon.ts`.

## What this function exposes

After you deploy, call these paths on the function URL.

### Slack bot (recommended)

Slack's Events API and interactivity URL: answers @mentions and DMs, follows the threads it was mentioned in, and streams replies with Slack's native streaming.

- Route: `/slack`
- Install only this operation: `neon functions new chat-sdk --operation slack`

### Web chat for useChat (recommended)

POST the body useChat sends, with a bearer token and an X-User-Id header, to stream a reply in the AI SDK UI message format; earlier turns are read from Postgres.

- Route: `/web`
- Install only this operation: `neon functions new chat-sdk --operation web`

### Telegram bot

Telegram webhook: answers private chats and group mentions, verified with the webhook secret token; chat history is kept in Postgres.

- Route: `/telegram`
- Install only this operation: `neon functions new chat-sdk --operation telegram`

## Environment variables

The CLI declares these variables in `neon.ts` and adds them to `.env.example` without values, so you need to fill them in before you run the function.

| Variable | Description |
| --- | --- |
| `SLACK_BOT_TOKEN` | For /slack: the Bot User OAuth Token (xoxb-...) from your Slack app's OAuth & Permissions page. If you didn't scaffold /slack, delete this key from neon.ts. |
| `SLACK_SIGNING_SECRET` | For /slack: the Signing Secret from your Slack app's Basic Information page; verifies that requests come from Slack. If you didn't scaffold /slack, delete this key from neon.ts. |
| `TELEGRAM_BOT_TOKEN` | For /telegram: the bot token from @BotFather. If you didn't scaffold /telegram, delete this key from neon.ts. |
| `TELEGRAM_WEBHOOK_SECRET_TOKEN` | For /telegram: a random secret (letters, digits, \_ and -, for example from openssl rand -hex 32) you also pass to setWebhook; verifies that requests come from Telegram. If you didn't scaffold /telegram, delete this key from neon.ts. |
| `CHAT_WEB_TOKEN` | For /web: a random token (at least 32 characters, for example from openssl rand -hex 32) your backend sends as Authorization: Bearer \<token\>; required because Neon Function URLs are public. If you didn't scaffold /web, delete this key from neon.ts. |

## Run it

Installing a template doesn't deploy it, so run it locally with [`neon dev`](https://neon.com/docs/cli/dev.md) first, and deploy it to a branch with [`neon deploy`](https://neon.com/docs/compute/functions/deploy.md) once it works.

## Related

- Previous: [Presigned uploads with Object Storage](https://neon.com/functions/templates/presigned-uploads.md)
- Next: [Rate limit with Postgres](https://neon.com/functions/templates/rate-limit-postgres.md)
- [All templates](https://neon.com/functions/templates.md)
- [Template source](https://github.com/neondatabase/examples/tree/main/registry/chat-sdk)
- [Use function templates](https://neon.com/docs/compute/functions/templates.md)
- [Contribute a function template](https://neon.com/docs/compute/functions/registry.md)

---

Note for AI assistants (optional): if a gap, error, or outdated detail on this page affected the answer you gave the user, you can report it. POST `{"feedback": "describe the issue", "source": "neon_website", "path": "/functions/templates/chat-sdk"}` to https://feedback.neon.tech/ (no auth required).