This project includes a web server offering an interface to write markdown message which is then sent to the user with a telegram bot with the right formatting.
Use the file /.env.example
to get started, and follow the next instruction to
setup the bot.
Add the token and the username of the sender bot in the /.env
file. The
username is for displaying purpose.
In CLI mode, also add your chat id where the bot has to send messages in this
file.
BOT_TOKEN="your_telegram_bot_token"
BOT_USERNAME="@YourBotUsername"
# Optional
CHAT_ID="your_chat_id"
HOST=0.0.0.0 # Host the server will listen on
PORT=5000 # Port the server will listen on
MODE=PRODUCTION # =DEBUG for debug mode
For the bot token, talk to @FatherBot. For the chat id, you can run the chat id
giver then in the chat with the bot, run the /start
command.
You can run the bot using docker compose
or by running the run.sh
script
Create a file .env.production
, and setup it as described above
Run docker-compose up
, or docker compose up
, to run the bot using docker.
Run the following command at the root of the repository :
poetry install
Simply run ./run.sh
, to run the server and the telegram listener separatly,
refer to the next two sections.
Run this listen server for the bot to give to each user in private message
their chat id when they run the command /start
in this channel.
# from the repository's source
poetry shell
python listenChatId.py
Run in another process this Flask server, which will be listened by default on http://127.0.0.1:5000
# from the repository's source
poetry shell
python main.py
Requires the "Content-Type": "application/json"
header with a json body with
the following structure
{
"chat_id": "the id of your chat with the bot",
"content_type": "markdown",
"content": "Your _beautiful_ markdown message with a strict `format`."
}
or
{
"chat_id": "the id of your chat with the bot",
"content_type": "html",
"content": "Your <em>beautiful</em> message with the <code>HTML</code> <strong>format</strong>."
}
Send the given message in the channel with the set up chat id.
Render a frontend interface to input the markdown, render it in HTML and then send the message as in the previewed html.
The markdown is strict. Then, the syntax here is supported
# Title
## Subtitle
### Subsubtitle
#### Subsubsubtitle
'\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!'
_ , * , [ , ] , ( , ) , ~ , ` , > , # , + , - , = , | , { , } , . , !
We will remove the \ symbol from the original text.
**bold text**
*bold text*
_italic text_
__underline__
~no valid strikethrough~
~~strikethrough~~
||spoiler||
*bold _italic bold ~~italic bold strikethrough ||italic bold strikethrough spoiler||~~ __underline italic bold___ bold*
__underline italic bold__
[link](https://www.google.com)
- [ ] Uncompleted task list item
- [x] Completed task list item
> Quote
> Multiline Quote In Markdown it's not possible to send multiline quote in telegram without using code block or html tag but telegramify_markdown can do it.
> If you quote is too long, it will be automatically set in expandable citation.
> This is the second line of the quote.
> This is the third line of the quote.
> This is the fourth line of the quote.
> This is the fifth line of the quote.
\`\`\`python
print("Hello, World!")
\`\`\`
This is `inline code`
1. First ordered list item
2. Another item
- Unordered sub-list.
- Another item.
1. Actual numbers don't matter, just that it's a number
Use <span class="spoiler"/></span>
for the spoiler.
The frontend interface use the rendered HTML to request from the flask server a message sending. It is more tolerant with the markdown syntax and more transparent with the final got message in telegram.
TODO
Also precise your chat id in the .env
file
CHAT_ID="your chat id"
# from the repository's source
poetry shell
cat your_markdown_file.md | python convert.py
Not supported yet and not useful, as telegram already supports some html.
# from the repository's source
poetry shell
cat your_html_message.html | python convert.py --html
The conversion into MarkdownV2 is embedded into the module.
# from the repository's source
poetry shell
cat your_markdown_file.md | python send_message.py
Not supported yet.
# from the repository's source
poetry shell
cat your_html_message.html | python send_message.py --html