Socket
Book a DemoInstallSign in
Socket

@dlghq/dialog-node-client

Package Overview
Dependencies
Maintainers
6
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dlghq/dialog-node-client

Dialog Node.js client =====================

0.9.1
latest
npmnpm
Version published
Maintainers
6
Created
Source

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

FAQs

Package last updated on 08 Feb 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.