I use django-telegrambot package to make anti-spam telegram bot. The mode for the bot is WEBHOOK
I have some functionality to remove all forwarded messages from chat.
My code looks like:
if update.message.forward_from or update.message.forward_from_chat:
bot.delete_message(chat_id=update.message.chat_id, message_id=update.message.message_id)
return
the code above doesn't work very well, for example when I select a few messages and send them to channel, it deletes only one(sometimes two) messages from forwarded set, sometimes it even doesn't delete if I forward one message, I checked if we always have forward_from and forward_from_chat when forwarding, yes -- we always have it, also I thought I just have some amount of pending_update_count, but it's 0
I know django-telegrambot based on python-telegram-bot package when I have the same code using only python-telegram-bot and run it locally like python main.py it works perfect(catch and delete all forwarded messages)
Did someone face with such error here?
Any thinks/suggestions?
Thanks!
So ok, after investigating I didn't find where is the trouble here, but when I changed the mode from WEBHOOKto POLLING -- it works perfectly without any errors
Related
I have been trying to update my discord bot to discord.py v2.0 and wanted to switch over to slash commands and cogs. When trying different techniques of achieving this I once used py-cord. I created a test command called latency and it worked but since I struggled with py-cord I uninstalled py-cord and found a new technique. The problem is that the latency (my py-cord) command is still there on the list where you can choose what slash command to use and so I wonder how do I remove this from the bot command selection?
When working with slash commands, the discord API registers and deregisters the slash commands on their own servers, and then sets up hooks for your bot.
This means that, when the bot connects, it sends an API call to discord to tell it what commands it has, after which you need to wait for Discord to register that properly. They don't guarantee to do that instantly, not for deletion nor registration.
So, in short, you don't remove it from the bot section; you wait until Discord does that for you. They guarantee that they do that in 24 hours of your bot being online, but, realistically, it's usually done in less than 2.
You can set debug_guilds if you want to register commands faster, which would allow you to have a few guilds (servers) that would get updated first, usually quite close to immediately. However, from my own experience, that helped very little for deletion, as Discord usually took its time for that.
One more advantage of debug_guilds is that, when passed, any new or deleted commands are only registered for those specific guilds, allowing you for more free testing. However, it is not perfect, as changed excising commands are of course still run trough your testing bot.
Instead, my advice would be this: Create a second bot, and use that one for testing stuff. Once it's done, you can update the new bot with the verified code. This way, no one gets annoyed at multiple registered commands and all that! If you know how to use git: just run one bot on the main branch, and the other on the development branch. :-)
I hope this helps! :-)
I want when someone sends a message in Telegram, the information of the message is stored in the telegram bot or something else without seeing the other party's message.
I assume you want to do what is known as "ghost mode" which means you read messages but they're not double-checked.
Before I answer your question, I should warn you that Telegram's founder is against such use (see https://twitter.com/durov/status/891227609706536960).
The fun fact is you don't have to do anything to avoid double-checking a message. In fact there is an extra step for that. Therefore, all you need to do is to read the message. You can do so in telethon as simple as this:
#app.on(events.NewMessage())
def read(event):
print(event.message.message)
So there is an app called tandem, and it's on BlueStacks the android emulator, and I need to send automated messages to people I have followed on that app, without me having to scroll through everyone and sending them messages one by one, is there a way for me?
This app is not available on the web, so I have to use bluestacks.
Someone successfully made a spam bot using Python here, but that was for whatsapp.
Here's what I meant by having followed a list of users.
Also, I want to know how I can make it so that, if there is a specific sentence written, that the bot would spam another message instead. Let's say I write ”hello, how are you?” and the bot goes through other messages with the exact same messages, and spam another automated message, like ” I am doing great thanks”?
I have a doubt. I've been looking for information and haven't found anything. I would like to know if it is possible to send a message with a bot which will be eliminated after a certain time. I'm working with c# but I think other examples will work for me. Thanks in advance.
I thought I would delete my own message after a while but I think it would not be a solution in a well active chat, since there are many messages coming in all the time and I would not know for sure what the id of the message I sent is. I would have to do another algorithm to find out what that id is, and what I was trying to see is if there was some simpler method already implemented in the api for these specific cases. Send messages using the bot with self-destruct after a while.
I'm not sure if telegram API provides that.
but you can implement it in the bot to do that, maybe with "time" or "schedule" in python
I'm building a chatbot with wit.ai and python and integrating it with Facebook Messenger. I have set up webhooks as well as send function and fb_message function exactly like in this tutorial: https://github.com/wit-ai/pywit/blob/master/examples/messenger.py
My bot works fine when I test it in wit.ai or in console, but when I test it in actual Facebook Messenger, it gives each reply twice. It doesn't matter which function inside the bot gets called, I always get two replies.
My most simple action is this:
def defaultAnswer(request):
context = request['context']
return context
(This returns always the same string, which is defined in wit.ai engine.)
If your bot is subscribed to events other than pages_messaging, like messaging_deliveries, make sure you're handling this event as well.
What's happening is your that bot is receiving the message request, then receiving another one by another event, and your code is handling them both as messages.
I think this is the problem, and if it's not, give us more details about it.
Someone might have a case like mine.
My case:
I mistakenly subscribe my two different bots to one facebook page on the developer.facebook.com.
Due to the this mistake, when i write a specific command(e.g. restart) to my facebook page, bot replies exactly same two messages(e.g. "Bot Restarted", "Bot Restarted") to me.
It made me a crazy to find out the problem.
You should subscribe one bot to your facebook page at most.
I had this issue before and it turns out, the message_echoes was enabled. What happens essentially if this is enabled is that the Bot will try to echo whatever you text you entered.
My logic ended up catching the echo and then responded with the same response. I do have a handler to catch similar responses so I was able to avoid the infinite loop.