iobroker-community-adapters/ioBroker.telegram

sendig photo example uses outdated request package

JojoS62 opened this issue · 0 comments

Describe the bug
The example for sending an image was a good example to start, but it did not work with my camera. With some great help from a discord user we found that
1.) the authentication needed a sendImmediately=false
2.) the encoding in request.get() had to be set to 'null'

However, the require package is marked as deprecated as stated here:
request/request#3142

To Reproduce
Steps to reproduce the behavior:

  1. use example https://github.com/iobroker-community-adapters/ioBroker.telegram/blob/master/docs/en/README.md#usage
  2. See error 'unauthorized' in err.messageText response and/or invalid image is written to tmp/snap.jpg
  3. telegram rejects to send an empty message or the invalid image isn't shown

Expected behavior
a valid jpg image should we written to tmp and sent via telegram api

Screenshots & Logfiles

Versions:

  • Adapter version: 3.0.0
  • JS-Controller version: 5.0.16
  • Node version: 18.18.2
  • Operating system: debian

Additional context

modified example code with fixed items 1) 2), but still using request package:

var request = require('request');

function sendImage() {
    request
        .get({url: 'http://ip-of-camera/cgi-bin/snapshot.cgi?Channel=0',
              encoding: null},  // encoding null for write to buffer
              (error, response, body) => {
            sendTo('telegram.0', {text: body, type: 'photo'});
            log('image sent size: ' + body.length);
        })
        .auth('user',  'password', false)
    ;
}

This example could be added, for replacing the request package I don't have a solution yet. This example also uses a buffer instead of a temporary file.