Package: telegram-periodic-msg-bot
Telegram Periodic Message BotIntroductionTelegram bot for sending periodic messages in groups based onpyrogram.A single bot instance can be used with multiple periodic messages (with different periods) and in multiple groups.SetupCreate Telegram appIn order to use the bot, in addition to the bot token you also need an APP ID and hash.To get them, create an app using the following website:https://my.telegram.org/apps.InstallationThe package requires Python 3, it is not compatible with Python 2.To install it:Usingsetuptools:python setup.py installUsingpip:pip install telegram_periodic_msg_botTo run the bot, edit the configuration file by specifying the API ID/hash and bot token. Then, move to theappfolder and run thebot.pyscript:cd app
python bot.pyWhen run with no parameter,conf/config.iniwill be the default configuration file (in this way it can be used for different groups).To specify a different configuration file:python bot.py -c another_conf.ini
python bot.py --config another_conf.iniOf course, theappfolder can be moved elsewhere if needed.ConfigurationAn example of configuration file is provided in theapp/conffolder.The list of all possible fields that can be set is shown below.NameDescription[pyrogram]Configuration for pyrogramsession_nameSession name of your choiceapi_idAPI ID fromhttps://my.telegram.org/appsapi_hashAPI hash fromhttps://my.telegram.org/appsbot_tokenBot token from BotFather[app]Configuration for appapp_is_test_modeTrue to activate test mode false otherwiseapp_lang_fileLanguage file in XML format (default: English)[task]Configuration for taskstasks_max_numMaximum number of running tasks (totally, in all groups). Default: 20.[message]Configuration for messagemessage_max_lenMaximum message length in characters. Default: 4000.[logging]Configuration for logginglog_levelLog level, same of python logging (DEBUG,INFO,WARNING,ERROR,CRITICAL). Default:INFO.log_console_enabledTrue to enable logging to console, false otherwise (default:true)log_file_enabledTrue to enable logging to file, false otherwise (default:false). If false, all the next fields will be skipped.log_file_nameLog file namelog_file_use_rotatingTrue for using a rotating log file, false otherwiselog_file_max_bytesMaximum size in bytes for a log file. When reached, a new log file is created up tolog_file_backup_cnt. Valid only iflog_file_use_rotatingis true.log_file_backup_cntMaximum number of log files. Valid only iflog_file_use_rotatingis true.log_file_appendTrue to append to log file, false to start from a new file each time. Valid only iflog_file_use_rotatingis false.Supported CommandsList of supported commands:help: show this messagealive: show if bot is activemsgbot_set_test_mode true/false: enable/disable test modemsgbot_is_test_mode: show if test mode is enabledmsgbot_version: show bot versionmsgbot_task_start MSG_ID PERIOD_HOURS [START_HOUR] MSG: start a message task in the current chat. If the taskMSG_IDalready exists in the current chat, an error message will be shown. To start it again, it shall be stopped with themsgbot_task_stopcommand.Parameters:MSG_ID: Message IDPERIOD_HOURS: Task period in hours, it shall be between 1 and 24START_HOUR(optional): Task start hour, it shall be between 0 and 23. Default value: 0.MSG: Message to be sent periodically, it shall be on a new linemsgbot_task_stop MSG_ID: stop the specified message task in the current chat. If the taskMSG_IDdoes not exist in the current chat, an error message will be shown.Parameters:MSG_ID: CoinGeckoIDmsgbot_task_stop_all: stop all message tasks in the current chatmsgbot_task_pause MSG_ID: pause the specified message task in the current chat. If the taskMSG_IDdoes not exist in the current chat, an error message will be shown.Parameters:MSG_ID: Message IDmsgbot_task_resume MSG_ID: resume the specified message task in the current chat. If the taskMSG_IDdoes not exist in the current chat, an error message will be shown.Parameters:MSG_ID: Message IDmsgbot_task_get MSG_ID: show the message set for the specified message task in the current chat.Parameters:MSG_ID: Message IDmsgbot_task_set MSG_ID MSG: set the message of the specified message task in the current chat.Parameters:MSG_ID: Message IDMSG: Message to be sent periodically, it shall be on a new linemsgbot_task_delete_last_msg MSG_ID true/false: enable/disable the deletion of last messages for the specified message task in the current chat. If the taskMSG_IDdoes not exist in the current chat, an error message will be shown.Parameters:MSG_ID: Message IDflag: true or falsemsgbot_task_info: show the list of active message tasks in the current chatMessages can contain HTML tags if needed (e.g. for bold/italic text), while Markdown tags are not supported.By default, a message task will delete the last sent message when sending a new one. This can be enabled/disabled with themsgbot_task_delete_last_msgcommand.The task period starts from the specified starting hour (be sure to set the correct time on the VPS), for example:A task period of 8 hours starting from 00:00 will send the message at: 00:00, 08:00 and 16:00A task period of 6 hours starting from 08:00 will send the message at: 08:00, 14:00, 20:00 and 02:00ExamplesSend a periodical message every 8 hours starting from 00:00 in the current chat:/msgbot_task_start test_msg 8
Hi,
This is a <i>periodic message</i>.
<b>Bye!</b>Pause/Resume/Stop the previous task:/msgbot_task_pause test_msg
/msgbot_task_resume test_msg
/msgbot_task_stop test_msgShow the message set for the previous task:/msgbot_task_get test_msgSet a new message set for the previous task:/msgbot_task_set test_msg
Hello,
This is a <i>different periodic message</i>.
<b>Bye bye!</b>Set task so that it doesn't delete the last sent message:/msgbot_task_delete_last_msg test_msg falseSend a periodical message every 6 hours starting from 10:00 in the current chat:/msgbot_task_start test_msg 6 10
Periodic message with start hourRun the BotIt'd be better if the bot is an administrator of the group. This is mandatory if it needs to delete the last sent messages.In order to send messages periodically, the bot shall run 24h/24h so it's suggested to run it on a VPS (there is no performance requirements, so a cheap VPS will suffice).Test ModeDuring test mode, the bot will work as usual but the task period will be applied in minutes instead of hours. This allows to quickly check if it is working.TranslationThe messages sent by the bot on Telegram can be translated into different languages (the default language is English) by providing a custom XML file.The XML file path is specified in the configuration file (app_lang_filefield).An example XML file in italian is provided in the folderapp/lang.LicenseThis software is available under the MIT license.