Skip to content

Commit

Permalink
Improve docs a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
lkubb committed Oct 4, 2024
1 parent eb9fb19 commit 61aaca3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 39 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Salt Extension for interacting with Telegram
:hidden:

topics/installation
topics/configuration

.. toctree::
:maxdepth: 2
Expand Down
22 changes: 22 additions & 0 deletions docs/topics/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Configuration
## General
In order to send a message via Telegram, you need to provide a `chat_id` and a `token`.
If you don't pass them as parameters when calling functions from the execution module,
they need to be defined inside the minion configuration or the pillar.
These configuration values can be specified in either of the following ways:

```yaml
telegram:
chat_id: '123456789'
token: '00000000:xxxxxxxxxxxxxxxxxxxxxxxx'
```
```yaml
telegram.chat_id: '123456789'
telegram.token: '00000000:xxxxxxxxxxxxxxxxxxxxxxxx'
```
## Returner
Using the returner module requires the above configuration values
to be set in either the minion configuration or the pillar.
26 changes: 15 additions & 11 deletions src/saltext/telegram/beacons/telegram_bot_msg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
"""
Beacon to emit Telegram messages
Beacon to emit Telegram messages.
Configuration example
---------------------
Include the following in the minion configuration:
.. code-block:: yaml
beacons:
telegram_bot_msg:
- token: "<bot access token>"
- accept_from:
- "<valid username>"
- interval: 10
"""

import logging
Expand Down Expand Up @@ -56,16 +70,6 @@ def beacon(config):
"""
Emit a dict with a key "msgs" whose value is a list of messages
sent to the configured bot by one of the allowed usernames.
.. code-block:: yaml
beacons:
telegram_bot_msg:
- token: "<bot access token>"
- accept_from:
- "<valid username>"
- interval: 10
"""

config = salt.utils.beacons.list_to_dict(config)
Expand Down
14 changes: 3 additions & 11 deletions src/saltext/telegram/modules/telegram.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
"""
Module for sending messages via Telegram.
:configuration: In order to send a message via the Telegram, certain
configuration is required in /etc/salt/minion on the relevant minions or
in the pillar. Some sample configs might look like::
telegram.chat_id: '123456789'
telegram.token: '00000000:xxxxxxxxxxxxxxxxxxxxxxxx'
"""

import logging
Expand All @@ -34,7 +26,7 @@ def __virtual__():

def _get_chat_id():
"""
Retrieves and return the Telegram's configured chat id
Retrieve and return the Telegram's configured chat id
:return: String: the chat id string
"""
Expand All @@ -49,7 +41,7 @@ def _get_chat_id():

def _get_token():
"""
Retrieves and return the Telegram's configured token
Retrieve and return the Telegram's configured token
:return: String: the token string
"""
Expand Down Expand Up @@ -93,7 +85,7 @@ def _post_message(message, chat_id, token):
Send a message to a Telegram chat.
:param chat_id: The chat id.
:param message: The message to send to the telegram chat.
:param message: The message to send to the Telegram chat.
:param token: The Telegram API token.
:return: Boolean if message was sent successfully.
"""
Expand Down
20 changes: 3 additions & 17 deletions src/saltext/telegram/returners/telegram_return.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
"""
Return salt data via Telegram.
Return Salt data via Telegram.
The following fields can be set in the minion conf file::
telegram.chat_id (required)
telegram.token (required)
Telegram settings may also be configured as:
.. code-block:: yaml
telegram:
chat_id: 000000000
token: 000000000:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
To use the Telegram return, append '--return telegram' to the salt command.
To use the Telegram returner, append ``--return telegram`` to the Salt command.
.. code-block:: bash
salt '*' test.ping --return telegram
"""

import logging
Expand All @@ -37,7 +23,7 @@ def _get_options(ret=None):
:param ret: The data to be sent.
:return: Dictionary containing the data and options needed to send
them to telegram.
a message to Telegram.
"""
attrs = {"chat_id": "chat_id", "token": "token"}

Expand Down

0 comments on commit 61aaca3

Please sign in to comment.