ciresbot


Nameciresbot JSON
Version 0.2.4 PyPI version JSON
download
home_page
SummaryTelegram bot
upload_time2024-03-16 19:28:58
maintainer
docs_urlNone
author
requires_python>=3.11
license
keywords telegram bot messaging
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Telegram Bot

Send data through the telegram bot API. Currently, supports sending messages
and photos.

## Installation

Install with pip

```
pip install ciresbot
```

## Usage

### Python Module

Creating a bot requires only its token. To send messages or photos it needs
to know the chat id of the recipient(s) (see below how to obtain the chat ids).

```python
from telegrambot import TelegramBot

bot = TelegramBot("MyBotToken")
bot.send_message("Hello World", chat_id="12345")
bot.send_photo("./dog.jpg", caption="Cute dog", chat_id="12345")
```

Ideally, the token bot should not be hardcoded, the module also comes with some utilities
to read your tokens from a file. It expects a csv file with the following format:

```csv
# tokens.csv
botName,token
MyBot,MyBotToken12345
```

Also, you can read your chats from a csv file:

```csv
chatName,chatId,bot
MyChat,12345,MyBot
```

If you have a file with the above specifications you can use the utility functions
as in the following example:

```python
from telegrambot import TelegramBot
from telegrambot.utils import read_token_file, get_chat_id

token = read_token_file("./tokens.csv", "MyBot")
if not token:
   raise ValueError("Token not found")
    
chat_id = get_chat_id("MyChat", "./chats.csv")
if not chat_id:
    raise ValueError("Chat id not found")

bot = TelegramBot(token)
success, status_code, message = bot.send_message("Hello", chat_id)
if success:
    print(f"Message sent successfully: {message}")
else:
    print(f"Failed to send message {status_code}")
```

### Command Line Tool

The command line tool supports the following modes:

- `message`: Send a text message through Telegram using a bot.
- `photo`: Send a photo through Telegram using a bot.
- `updates`: Get the latest updates of the bot from Telegram.

### Options

Common options that can be used with all modes:

- `--bot, -b`: Name or token of the bot that will be used (required).
- `--token, -t`: Whether a token was passed. If not, it is assumed that the bot name was passed.
- `--bot-file, -f`: Name of the CSV file containing the token(s) of the bot(s). Required if the bot name was passed.
- `--chat, -c`: Name or ID of the chat where the info will be sent (required).
- `--id, -i`: Whether a chat ID was passed. If not, it is assumed that the chat name was passed.
- `--chat-file, -cf`: Name of the CSV file containing the ID(s) of the chat(s). Required if the bot name was passed.

Specific options for each mode:

#### Message Mode

- `--message, -m`: Text of the message (required).

#### Photo Mode

- `--photo, -p`: Path to the photo file (required).
- `--caption, -cp`: A caption for the photo (optional).

### Examples

Sending a message using a bot:

```shell
telegrambot message --bot MyBot --message "Hello, World!" --chat MyChat --bot-file ./bot.csv --chat-file ./chat.csv
```

Sending a photo using a bot:

```shell
telegrambot photo --bot MyBot --photo ./photo.jpg --caption "A picture" --chat MyChat --bot-file ./bot.csv --chat-file ./chat.csv
```

Getting updates of a bot 

```shell
telegrambot updates --bot MyBot --bot-file ./bot.csv
```

### Obtaining chat ids

To obtain the chat id, first add the bot to a new chat or an existing one. Then send a message to the
chat. Wait a few seconds and after that get the updates of the bot, you can use the CLI. In the updates
the chat id will appear.

## License

Created by Daniel Ibarrola. It is licensed under the terms of the MIT license.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "ciresbot",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "telegram,bot,messaging",
    "author": "",
    "author_email": "Daniel Ibarrola <daniel.ibarrola.sanchez@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/92/a8/42dd6f9586d0c761d1508da659b8e9e41f750cfe72187f8caf83f30da36b/ciresbot-0.2.4.tar.gz",
    "platform": null,
    "description": "# Telegram Bot\n\nSend data through the telegram bot API. Currently, supports sending messages\nand photos.\n\n## Installation\n\nInstall with pip\n\n```\npip install ciresbot\n```\n\n## Usage\n\n### Python Module\n\nCreating a bot requires only its token. To send messages or photos it needs\nto know the chat id of the recipient(s) (see below how to obtain the chat ids).\n\n```python\nfrom telegrambot import TelegramBot\n\nbot = TelegramBot(\"MyBotToken\")\nbot.send_message(\"Hello World\", chat_id=\"12345\")\nbot.send_photo(\"./dog.jpg\", caption=\"Cute dog\", chat_id=\"12345\")\n```\n\nIdeally, the token bot should not be hardcoded, the module also comes with some utilities\nto read your tokens from a file. It expects a csv file with the following format:\n\n```csv\n# tokens.csv\nbotName,token\nMyBot,MyBotToken12345\n```\n\nAlso, you can read your chats from a csv file:\n\n```csv\nchatName,chatId,bot\nMyChat,12345,MyBot\n```\n\nIf you have a file with the above specifications you can use the utility functions\nas in the following example:\n\n```python\nfrom telegrambot import TelegramBot\nfrom telegrambot.utils import read_token_file, get_chat_id\n\ntoken = read_token_file(\"./tokens.csv\", \"MyBot\")\nif not token:\n   raise ValueError(\"Token not found\")\n    \nchat_id = get_chat_id(\"MyChat\", \"./chats.csv\")\nif not chat_id:\n    raise ValueError(\"Chat id not found\")\n\nbot = TelegramBot(token)\nsuccess, status_code, message = bot.send_message(\"Hello\", chat_id)\nif success:\n    print(f\"Message sent successfully: {message}\")\nelse:\n    print(f\"Failed to send message {status_code}\")\n```\n\n### Command Line Tool\n\nThe command line tool supports the following modes:\n\n- `message`: Send a text message through Telegram using a bot.\n- `photo`: Send a photo through Telegram using a bot.\n- `updates`: Get the latest updates of the bot from Telegram.\n\n### Options\n\nCommon options that can be used with all modes:\n\n- `--bot, -b`: Name or token of the bot that will be used (required).\n- `--token, -t`: Whether a token was passed. If not, it is assumed that the bot name was passed.\n- `--bot-file, -f`: Name of the CSV file containing the token(s) of the bot(s). Required if the bot name was passed.\n- `--chat, -c`: Name or ID of the chat where the info will be sent (required).\n- `--id, -i`: Whether a chat ID was passed. If not, it is assumed that the chat name was passed.\n- `--chat-file, -cf`: Name of the CSV file containing the ID(s) of the chat(s). Required if the bot name was passed.\n\nSpecific options for each mode:\n\n#### Message Mode\n\n- `--message, -m`: Text of the message (required).\n\n#### Photo Mode\n\n- `--photo, -p`: Path to the photo file (required).\n- `--caption, -cp`: A caption for the photo (optional).\n\n### Examples\n\nSending a message using a bot:\n\n```shell\ntelegrambot message --bot MyBot --message \"Hello, World!\" --chat MyChat --bot-file ./bot.csv --chat-file ./chat.csv\n```\n\nSending a photo using a bot:\n\n```shell\ntelegrambot photo --bot MyBot --photo ./photo.jpg --caption \"A picture\" --chat MyChat --bot-file ./bot.csv --chat-file ./chat.csv\n```\n\nGetting updates of a bot \n\n```shell\ntelegrambot updates --bot MyBot --bot-file ./bot.csv\n```\n\n### Obtaining chat ids\n\nTo obtain the chat id, first add the bot to a new chat or an existing one. Then send a message to the\nchat. Wait a few seconds and after that get the updates of the bot, you can use the CLI. In the updates\nthe chat id will appear.\n\n## License\n\nCreated by Daniel Ibarrola. It is licensed under the terms of the MIT license.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Telegram bot",
    "version": "0.2.4",
    "project_urls": {
        "Homepage": "https://github.com/Daniel-Ibarrola/TelegramBot.git"
    },
    "split_keywords": [
        "telegram",
        "bot",
        "messaging"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4f465706f8fca155111d7b616bc6f7288af7ca37b2cecba48b60792f5f8bdb8e",
                "md5": "5e4acea5da1f51151d29efeee617c7d4",
                "sha256": "e99f812327c51abab2d52af02cb576175ea517e0ca9aeeb7acdb8feb218113c4"
            },
            "downloads": -1,
            "filename": "ciresbot-0.2.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5e4acea5da1f51151d29efeee617c7d4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 7476,
            "upload_time": "2024-03-16T19:28:57",
            "upload_time_iso_8601": "2024-03-16T19:28:57.275399Z",
            "url": "https://files.pythonhosted.org/packages/4f/46/5706f8fca155111d7b616bc6f7288af7ca37b2cecba48b60792f5f8bdb8e/ciresbot-0.2.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "92a842dd6f9586d0c761d1508da659b8e9e41f750cfe72187f8caf83f30da36b",
                "md5": "d87c922ad5fcc3550d20a3e8758037da",
                "sha256": "8db91046469fe8414e33693b55b6dbed1d9ccc03edbd0923c71bf737d0a7acfe"
            },
            "downloads": -1,
            "filename": "ciresbot-0.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "d87c922ad5fcc3550d20a3e8758037da",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 6386,
            "upload_time": "2024-03-16T19:28:58",
            "upload_time_iso_8601": "2024-03-16T19:28:58.804968Z",
            "url": "https://files.pythonhosted.org/packages/92/a8/42dd6f9586d0c761d1508da659b8e9e41f750cfe72187f8caf83f30da36b/ciresbot-0.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-16 19:28:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Daniel-Ibarrola",
    "github_project": "TelegramBot",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "ciresbot"
}
        
Elapsed time: 0.20473s