V
V
Vlad2021-12-02 13:33:07
Node.js
Vlad, 2021-12-02 13:33:07

How to transfer data from Websocket to Telegram bot?

Hello. Actually there is a web socket of a third-party service, according to changes in the LC of the service, I receive data on the socket. Everything is ok here. Now you need to transfer them to the bot in the cart. Created a bot, responds to commands.
I don't understand how to tie this together. I don't need commands to be written to the bot, except for the first default /start.
I need the message coming on the socket to be immediately sent to the bot.
How to do it?

this._ws.onmessage = (msg) => {
      try {
        const message = JSON.parse(msg.data);

        bot.onText(/\/echo (.+)/, (msg, match) => {
             const chatId = msg.chat.id;

            bot.sendMessage(chatId, message); // по сути мне нужен только этот метод, но без chatId он работать не будет
            // как мне избавится от тригера bot.onText? 
         });
      } catch (e) {
        logger.warn('Parse message failed', e);
      }
    };

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Python Newbie, 2021-12-02
@Levman5

Do if a message arrives on the socket, then send messages to any chat id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question