https://github.com/nushell-prophet/nu-telegram-bot
https://github.com/nushell-prophet/nu-telegram-bot
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/nushell-prophet/nu-telegram-bot
- Owner: nushell-prophet
- License: unlicense
- Created: 2024-03-30T13:24:28.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-16T10:14:13.000Z (almost 2 years ago)
- Last Synced: 2024-09-28T21:05:02.322Z (over 1 year ago)
- Language: Nushell
- Size: 31.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nu - nu-telegram-bot
README
# nu-telegram-bot
[](http://unmaintained.tech/)
A basic Nushell module for interacting with the Telegram Bot API.

# Quick start
1. Clone this repository
```nu no-run
> git clone https://github.com/nushell-prophet/nu-telegram-bot
> cd nu-telegram-bot
> use nutgb.nu
```
2. Obtain the token for your bot from [@botfather](https://t.me/botfather) and add it to `nutgb`
```nu no-run
nutgb add-bot
```
3. Send any message to your new bot from the account that will later receive messages from the bot.
(optionally, you can add this bot to the group or channel).
4. Receive updates (sent messages to the bot or events of adding him to groups).
Mind that you can use `tab` auto-completion for the bot's name here.
```nu no-run
nutgb get-updates
```
5. If the previous command gave you some data, it means that now you can send messages using `nutgb send-message`
```nu no-run
nutgb send-message 'some message' --recipient
```
`nutgb` saves tokens and conversations with users:
1. If `$env.nutgb-path` is set - in that folder.
2. If `$env.XDG_CONFIG_HOME` is set, then in `nutgb` folder inside.
3. Otherwise, in `.nutgb` folder in home `$nu.home-path`.
You are welcome to read the code and make your understanding.
The part about locating needed files is described [here](https://github.com/nushell-prophet/nu-telegram-bot/blob/a4528eef02de23e9faa0054304cce46f35ef584e/nutgb.nu#L167).
# commands help
```nushell
use nutgb.nu
nutgb add-bot -h
```
Output:
```
add a Telegram bot using the provided token and optionally return bot information
Usage:
> add-bot {flags}
Flags:
--return_info - if set, returns bot information instead of saving it
--default - make this bot default for sending messages from
-h, --help - Display the help message for this command
Parameters:
bot_token : the bot token provided by Telegram's Botfather https://t.me/botfather
```
```nushell
nutgb get-updates -h
```
Output:
```
retrieve messages sent to a bot by users in last hours and save them locally
Usage:
> get-updates
Flags:
-h, --help - Display the help message for this command
Parameters:
bot_name : the name of the bot to retrieve updates for
```
```nushell
nutgb send-message -h
```
Output:
```
send a text message to a recipient via a bot
Usage:
> send-message {flags} (message_text)
Flags:
--silent_notification - if set, disables notification for the recipient
--text_format - the mode for parsing the message - 'MarkdownV2', 'Markdown', 'HTML' (default: '')
--recipient_id - the recipient of the message
--reply_to_id - the message ID to reply to (default: '')
--suppress_output - don't output send details
-h, --help - Display the help message for this command
Parameters:
message_text : the message text to be sent (optional)
```
```nushell
nutgb send-image -h
```
Output:
```
send an image or animation file to a recipient via a bot
Usage:
> send-image {flags} (media_path)
Flags:
--recipient_id - the recipient of the message
--text_format - the mode for parsing the message caption (default: '')
--media_caption - the caption for the image or animation (default: '')
--reply_to_id - the message ID to reply to (default: '')
--silent_notification - if set, disables notification for the recipient
--suppress_output - don't output send details
-h, --help - Display the help message for this command
Parameters:
media_path : the path to the image or animation file to be sent (optional)
```
```nushell
nutgb get-recipients -h
```
Output:
```
get a list of recipients for a bot, optionally updating the list
Usage:
> get-recipients {flags} (bot_name)
Flags:
--refresh_chat_list - if set, updates the recipient list by making a request
--set-default - set default recipient to omit setting in other commands
-h, --help - Display the help message for this command
Parameters:
bot_name : the name of the bot to retrieve recipients for (optional)
```