
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
@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
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.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.