@dlghq/dialog-node-client

0.9.1 • Public • Published

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(
  // endpoints
  ['wss://ws1.dlg.im'],
  // user credentials
  { phone: '75555555555', code: '5555' }
);

bot.onMessage(async (update) => {
  // get self uid
  const uid = await bot.getUid();

  // check if message contents photo
  if (update.content.type === 'photo') {
    // load photo url
    const url = await bot.loadFileUrl(update.content.file);
    // and send it back to the client
    await bot.sendTextMessage(update.peer, `Thanks for photo: ${url}`);

    // send file as image
    await bot.sendPhotoMessage(update.peer, path.resolve(__dirname, 'dinotocat.png'));
  } else {
    // send text message
    await bot.sendTextMessage(update.peer, 'Hello =)');
  }
});

// handle errors
bot.on('error', (error) => {
  console.error(error);
  process.exit(1);
});

More examples

Dependencies (4)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @dlghq/dialog-node-client

    Weekly Downloads

    1

    Version

    0.9.1

    License

    UNLICENSED

    Unpacked Size

    11.7 kB

    Total Files

    11

    Last publish

    Collaborators

    • timurkhabibullin