Dialog Node.js client
Installation
yarn add @dlghq/dialog-node-client
Usage
const path = require('path');
const { Bot } = require('@dlghq/dialog-node-client');
const bot = new Bot(
['wss://ws1.dlg.im'],
{ phone: '75555555555', code: '5555' }
);
bot.onMessage(async (update) => {
const uid = await bot.getUid();
if (update.content.type === 'photo') {
const url = await bot.loadFileUrl(update.content.file);
await bot.sendTextMessage(update.peer, `Thanks for photo: ${url}`);
await bot.sendPhotoMessage(update.peer, path.resolve(__dirname, 'dinotocat.png'));
} else {
await bot.sendTextMessage(update.peer, 'Hello =)');
}
});
bot.on('error', (error) => {
console.error(error);
process.exit(1);
});
More examples