I have the following telegram bot written in Python (3.x)
:
import telebot
import subprocess
from telebot import types
import os
bot = telebot.TeleBot(os.environ['BOT_API_TOKEN'])
@bot.message_handler(commands=['start'])
def save(messages):
for m in messages:
if "keyword" in m.text:
f = open("channel", "a")
f.write(m.text + "\n")
f.close()
bot.send_message(m.chat.id, "Saved!")
bot.set_update_listener(save)
bot.polling()
The idea is to store in the file channel
the messages that contain the word keyword
. This bot works perfectly if I talk to him, but if I add the bot to a channel, it doesn't work. The bot has disable the privacy mode and enable the joingroups option.
I have another bot that do the same but with different code: import logging import os from telegram.ext import Updater, MessageHandler, Filters
updater = Updater(token=os.environ['BOT_API_TOKEN'])
dispatcher = updater.dispatcher
def save(bot, update):
print(update.message.text)
if "keyword" in update.message.text:
f = open("channel", "a")
f.write(update.message.text + "\n")
f.close()
bot.sendMessage(chat_id=update.message.chat_id, text="Saved!")
save_handler = MessageHandler(Filters.text, save)
dispatcher.add_handler(save_handler)
updater.start_polling()
I don't mind in which version can you help me.