rainner / binance-watch

This application connects to the Binance.com public API to get live 24h price change data for all crypto trading pairs on their platform and allows you to set custom alerts or watch for price change in real time and get desktop notifications when something triggers your alerts or price watch settings.
MIT License
187 stars 80 forks source link

Telegram Bot API #44

Open abtahizadeh opened 1 year ago

abtahizadeh commented 1 year ago

Hi rainner

I think the Telegram Bot API section is not working Does it need to update the code?

OmarMai commented 1 year ago

Its and old repo, don't expect a update any time soon. Im trying to run the project and try to use a discord bot api instead

abtahizadeh commented 1 year ago

Its and old repo, don't expect a update any time soon. Im trying to run the project and try to use a discord bot api instead

Thanks This part of the code is related to Telegram


https://github.com/rainner/binance-watch/blob/b1f1cff2c624765bcc2c89a30f4fda30a6c5108e/src/modules/messenger.js#L140

  /**
   * Send queue messages using Telegram API
   */
  _telegramSend() {
    let { enabled, botkey, userid } = this._options.telegram;
    if ( !enabled || !botkey || !userid || !this._ajax ) return;
    let content = '';

    this._queue.forEach( q => {
      let { title, message } = q;
      content += `<b>${ title }</b> \n`;
      content += `${ message } \n`;
      content += `\n`;
    });

    const fdata = new FormData();
    fdata.append( 'chat_id', userid );
    fdata.append( 'text', String( content ).trim() );
    fdata.append( 'parse_mode', 'html' );

    this._ajax.post( 'https://api.telegram.org/bot'+ botkey +'/sendMessage', {
      type: 'json',
      data: fdata,
      done: ( xhr, status, response ) => {
        if ( !response || !response.ok ) return console.warn( 'Telegram-API', status, response );
        this.emit( 'sent', 'Telegram notifications sent to ('+ userid +').' );
      },
    });