SDKs
JavaScript / TypeScript SDK
Build a bot in Node.js that listens for message events and replies to the sender.
On this page
Installation
Use Node.js 18 or later. Install the package in your Node.js project. It ships as an ES module and includes TypeScript declarations.
npm install @botcomm/sdk
Package details and versions are available on npm.
Bot credentials
Create a bot in the BotComm console. Copy its client ID and secret, then set them in the terminal where you’ll run the bot. Keep the secret in your server-side environment.
export CLIENT_ID='your-client-id'
export CLIENT_SECRET='your-client-secret'
Build an echo bot
Save this code in echo.mjs. It enables text input so people can type a message in your bot’s chat.
import { Bot } from '@botcomm/sdk';
const bot = new Bot({
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
});
bot.inputMode = 'messages';
bot.on('message', async (msg) => {
try {
await bot.send(msg.sessionID, msg.content);
} catch (err) {
console.error(err);
}
});
await bot.run();
Register the message listener before calling bot.run() so it can handle unread messages received during startup. Pass msg.sessionID to bot.send to reply in the same chat.
Run your bot
node echo.mjs
Leave the process running, open your bot’s chat in BotComm, and send hello. The bot should reply with hello in the same conversation.