telegram.sh/README.md

32 lines
849 B
Markdown
Raw Normal View History

2021-09-02 18:13:01 +02:00
# telegram.sh, a telegram bot api library in bash
2022-04-03 17:28:50 +02:00
This library aims to make creating quick-and-dirty bots in Bash as easy
as possible. To create a basic bot, all you need is the following:
2021-09-02 18:13:01 +02:00
```
#!/bin/bash
source tg.sh
2022-04-03 17:28:50 +02:00
TELEGRAM_TOKEN="<token>"
2021-09-02 18:13:01 +02:00
function _on_msg() {
echo "${event[from_username]}: ${event[text]}"
if [[ "${event[text]}" == "o/" ]]; then
2022-04-03 17:28:50 +02:00
tg_send ${event[chat_id]} "$(_escape '\o')"
2021-09-02 18:13:01 +02:00
fi
}
tg_start
```
2022-04-03 17:28:50 +02:00
Please note how you need to *escape* the text if there are any characters
which would conflict with the MarkdownV2 standard. If you wish to use MD
styling, the `tg_send` call could look like that:
```
tg_send ${event[chat_id]} "[$(_escape "^_^")]($(_escape "https://example.org"))"
```
Alternatively, if you decide that you don't want to run `_escape` on every
string, set `ESCAPE_ALL` to `true` after loading the library.