File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/telegram.cpython-310.pyc
Back
o ;j! � @ s| d Z ddlZddlmZ zddlZdZW n ey dZY nw e�e�Z dZ dd� Zd d � Zdd� Z dd d�Zdd� ZdS )a[ 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' � N)�SaltInvocationErrorTFZtelegramc C s t sdS tS )zZ Return virtual name of the module. :return: The virtual name of the module. )FzMissing dependency requests)�HAS_REQUESTS�__virtualname__� r r �I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/telegram.py�__virtual__ s r c C �( t d d�pt d d�} | std��| S )zl Retrieves and return the Telegram's configured chat id :return: String: the chat id string � config.getztelegram:chat_idztelegram.chat_idzNo Telegram chat id found�Z__salt__r )�chat_idr r r �_get_chat_id( � �r c C r )zh Retrieves and return the Telegram's configured token :return: String: the token string r ztelegram:tokenztelegram.tokenzNo Telegram token foundr )�tokenr r r � _get_token7 r r c C s0 |st � }|s t� }| st�d� t| ||d�S )a� Send a message to a Telegram chat. :param message: The message to send to the Telegram chat. :param chat_id: (optional) The Telegram chat id. :param token: (optional) The Telegram API token. :return: Boolean if message was sent successfully. CLI Example: .. code-block:: bash salt '*' telegram.post_message message="Hello Telegram!" zmessage is a required option.��messager r )r r �log�error� _post_messager r r r �post_messageF s r c C s� d|� d�}t � }|r||d<