Skip to main content

Chatbot

The Nexconn Chat SDK supports chatbot integration. You can send messages to a chatbot and receive automated responses.

How it works

A chatbot is a special user registered on the server. Your app sends messages to the chatbot's user ID, and the chatbot responds through the same messaging channel.

Send a message to a chatbot

Send a message to a chatbot the same way you send a message to any user — by creating a DirectChannel with the chatbot's user ID.

TypeScript
import { DirectChannel, SendTextMessageParams } from '@nexconn/chat';

const channel = new DirectChannel('<chatbot-user-id>');

const params = new SendTextMessageParams({ text: 'Hello, chatbot!' });
const { code, data } = await channel.sendMessage(params);
if (code === 0) {
console.log('Message sent to chatbot:', data);
}

Receive chatbot responses

Chatbot responses arrive through the standard message listener:

TypeScript
import { NCEngine, MessageHandler, Message } from '@nexconn/chat';

NCEngine.addMessageHandler('chatbot-handler', new MessageHandler({
onMessageReceived({ messages }): void {
messages.forEach((msg) => {
console.log('Chatbot response:', msg);
});
},
}));
info

Chatbot configuration and management are handled through the server API and Console. The client SDK only provides messaging capabilities.