
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
@dlghq/dialog-bot-sdk
Advanced tools
Bot SDK for Dialog messenger.
npm install @dlghq/dialog-bot-sdk
import dotenv from 'dotenv';
import Bot from '@dlghq/dialog-bot-sdk';
import { flatMap } from 'rxjs/operators';
dotenv.config();
async function run(token: string, endpoint: string) {
const bot = new Bot({
token,
endpoints: [endpoint],
loggerOptions: {
name: 'example-bot',
level: 'trace',
prettyPrint: true,
},
});
const self = await bot.getSelf();
bot.logger.info(`I've started, post me something @${self.nick}`);
bot.updateSubject.subscribe({
next(update) {
bot.logger.info(JSON.stringify({ update }, null, 2));
},
});
const messagesHandle = bot.subscribeToMessages().pipe(
flatMap(async (message) => {
const author = await bot.forceGetUser(message.senderUserId);
if (author.isBot) {
await bot.sendText(message.peer, "Hi, I'm bot too!");
return;
}
}),
);
await new Promise((resolve, reject) => {
messagesHandle.subscribe({
error: reject,
complete: resolve,
});
});
}
const token = process.env.BOT_TOKEN;
if (typeof token !== 'string') {
throw new Error('BOT_TOKEN env variable not configured');
}
const endpoint =
process.env.BOT_ENDPOINT || 'https://grpc-test.transmit.im:9443';
run(token, endpoint).catch((error) => {
console.error(error);
process.exit(1);
});
In case your server requires mutual authentication, you can pass credentials like this.
import fs from 'fs';
import Bot from '@dlghq/dialog-bot-sdk';
const bot = new Bot({
token,
endpoints: ['https://epm.dlg.im'],
ssl: {
rootCerts: fs.readFileSync(path.join(__dirname, 'dialog-root-cert.crt')),
privateKey: fs.readFileSync(path.join(__dirname, 'client.key')),
certChain: fs.readFileSync(path.join(__dirname, 'client.crt')),
},
});
FAQs
Dialog Bot SDK
The npm package @dlghq/dialog-bot-sdk receives a total of 2 weekly downloads. As such, @dlghq/dialog-bot-sdk popularity was classified as not popular.
We found that @dlghq/dialog-bot-sdk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 33 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.