HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/telegram.cpython-310.pyc
o

�N�g!
�@s|dZddlZddlmZzddlZdZWneydZYnwe�e�Z	dZ
dd�Zd	d
�Zdd�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)�SaltInvocationErrorTFZtelegramcCstsdStS)zZ
    Return virtual name of the module.

    :return: The virtual name of the module.
    )FzMissing dependency requests)�HAS_REQUESTS�__virtualname__�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/telegram.py�__virtual__srcC�(tdd�ptdd�}|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_idrrr�_get_chat_id(��rcCr)zh
    Retrieves and return the Telegram's configured token

    :return:    String: the token string
    r	ztelegram:tokenztelegram.tokenzNo Telegram token foundr
)�tokenrrr�
_get_token7r
rcCs0|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.��messagerr)rr�log�error�
_post_messagerrrr�post_messageFs
rcCs�d|�d�}t�}|r||d<|r||d<ztj||dd�}|��}t�d|�Wnty8t�d�Yd	Sw|�d
d	�sNt�d|�d�|�d
��d	SdS)a
    Send a message to a Telegram chat.

    :param chat_id:     The chat id.
    :param message:     The message to send to the telegram chat.
    :param token:       The Telegram API token.
    :return:            Boolean if message was sent successfully.
    zhttps://api.telegram.org/botz/sendMessager�text�x)�data�timeoutz*Raw response of the telegram request is %sz#Sending telegram api request failedF�okz8Sending telegram api request failed due to error %s (%s)Z
error_code�descriptionT)	�dict�requestsZpost�jsonr�debug�	Exception�	exception�get)rrr�urlZ
parameters�response�resultrrrrbs,	
��r)NN)�__doc__�loggingZsalt.exceptionsrrr�ImportError�	getLogger�__name__rrrrrrrrrrr�<module>s �