roboCop Telegram-Bot developed using the Telegram Bot API Methods to generated Robot Framework's Keywords.
The purpose of this is help when finish the develop/tests receive notify of the roboCop Telegram-Bot.
-
- Windows: Get last git here. Git Bash is recommended to work from Windows with almost the same features as Git on Linux.
-
- Windows: get last Python installer here
Hint: On Git Bash you can find where Python is located run
which python
orwhich python3
. Then you can set your path accordingly the correct Python version.
-
After cloning the project repository, then create the Python Virtual Environment
env
(can be the name you want)cd ~/roboCopChatBot-Telegram $ python -m venv env
Hint:
py -m pip install --user virtualenv
To install the python virtual environment
-
Add path setting to activate script
echo -e "\n# Sets PYTHONPATH var within virtualenv\nexport PYTHONPATH=$(pwd)" >> ./env/Scripts/activate
-
Activate the Virtual Environment, then you should see the (env) prefix in your bash prompt.
user@host: ~/roboCopChatBot-Telegram (branch) $ source ./env/Scripts/activate (env)
Hint: To exit
virtualenv
just typedeactivate
. To close Git Bash window typeexit
.
-
(env) $ pip install -r requirements.txt
Hint You can run this command on the Python virtual Environment.
VS Code is the recommended IDE, although barely anyone can be used. These are suggested VS Code plugins that best fit this automation project:
- Python - a must have for all Python developers.
- Robot Code - this is a very stronger robot framework extension. PS: The Robot Framework Intellisense extension has been deprecated.
- YAML - YAML plugin supported by Red Hat, so no further comments.
- Material Icon Theme - Optional but great extension to give a nice touch on file icons.
- JSON Pretty Printer - Optional but great extension to give a nice .json indentation.
- Path Intellisense - Optional but great extension to give autocomplete filenames.
- Code Spell Checker - Optional but a great extension to check that works well with code and documentation.
-
First make a copy of file
telegram_variables_template.py
to your home user folder and remove the-template
suffix. -
File
telegram_variables
has all initial variables to run RF and you have to change to fit your machine settings as needed, since it won't be committed anyway as each automation developer can have different settings:HOST_GET_UPDATES = "https://api.telegram.org/bot{token}/getMe"
A simple method for testing your bot's auth token. There's a… bot for that. Just talk to BotFather and follow a few simple steps. Once you've created a bot and received your authentication token, head down to the Bot API manual to see what you can teach your bot to do.HOST_SEND_MESSAGE = "https://api.telegram.org/bot{token}/sendMessage"
Use this method to send text messages. On success, the sent Message is returned.CHAT_ID = "YOURCHATID"
Take the {YOURCHATID} value, it should be around 9 numbers. IMPORTANT: It's a security best practice to NEVER commit HOST_GET_UPDATES, HOST_SEND_MESSAGE and CHAT_ID in code repositories.
-
File
payload_template.json
contain theBODY PARAMS
.chat_id
is the Unique identifier for the target chat or username of the target channel (in the format@channelusername
).text
to text of the message to be sent.parse_mode
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. Optionaldisable_web_page_preview
a boolean PARAM disables link previews for links in this message.disable_notification
boolean sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound. Other apps coming soon.reply_to_message_id
if the message is a reply, ID of the original message.reply_markup
additional interface options. A JSON-serialized object for a custom reply keyboard, instructions to hide keyboard or to force a reply from the user. -
To run the
demo
test tag from demo.robot suite on another Git Bash / terminal window, activate the Python Virtual Environment as stated before and use this command:(env) $ robot --variablefile ./resources/python-telegram-bot/telegram-variables/telegram_variables.py --loglevel DEBUG --outputdir results ./tests/demo.robot