edisonchee / slimbot

Telegram Bot API for Node.js
MIT License
223 stars 37 forks source link

How to use “deleteMessage” method in Telegram bot api? #9

Closed ViacheslavLabs closed 7 years ago

ViacheslavLabs commented 7 years ago

I adding new feature to my telegram bot, and I can`t run deleteMessage method. In this code when I or anyone in chat write message, bot must delete it.

Also bot has can_delete_messages permission in a supergroup. And I try it many times and nothing. I can easy send messages, but can't delete not bot's messages or anybody else.

Here code, which returns undefined undefined

const Slimbot = require('slimbot');
const slimbot = new Slimbot('I hide it');

    function callback(err, obj) {
    if (err) {
    // handle error
    console.log(obj);   
    }
    // handle returned object
    console.log(obj);
    };

slimbot.on('message', message => {

    if (message.text) {
    if (true){          
        slimbot.deleteMessage(message.chat.id,message.message_id, callback);
        }
    }
});

slimbot.startPolling(callback);

Questions:

1)"undefined" are from callback function, but it doesn`t provide any normal information. How make normal error feedback?

2) How to run deleteMessage method properly?

okolilemuel commented 7 years ago

@ViacheslavLabs how did you resolve the problem with the deleteMessage method?

I am having the same issues right now, and have no clue on how to fix it.

okolilemuel commented 7 years ago

@edisonchee How to run deleteMessage method properly?

ViacheslavLabs commented 7 years ago

@xerxe6 My bot code part was short, so i decided to use another module - telegraf .

okolilemuel commented 7 years ago

@ViacheslavLabs ok

okolilemuel commented 7 years ago

@edisonchee ????

edisonchee commented 7 years ago

hi @xerxe6, I've just fixed the bug where the callback function returns undefined. Please update the package via npm and try again.

prabil commented 6 years ago

If there any bot to automatically delete any message comes to group

edisonchee commented 6 years ago

@prabil do you mind opening a new issue if it's not related to this?

bekbull commented 5 years ago
def delete_msg(bot, update):
    print(update.message.message_id, type(update.message.message_id))
    for i in range(50):
        bot.deleteMessage(chat_id=update.message.chat_id, message_id=608 + 1)

I am trying to delete messages, but there is a thing. The bot can call the method, but cannot process the cycle. aaaaaaaaaaaaaa