
    Vh                     t    d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d dlmZ d dlmZ d	 Zed
k(  r e        yy)    )absolute_importdivisionprint_functiona?  
module: telegram
author:
  - "Artem Feofanov (@tyouxa)"
  - "Nikolai Lomov (@lomserman)"

short_description: Send notifications using telegram

description:
  - Send notifications using telegram bot, to a verified group or user.
  - Also, the user may try to use any other telegram bot API method, if you specify O(api_method) argument.
notes:
  - You will require a telegram account and create telegram bot to use this module.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  token:
    type: str
    description:
      - Token identifying your telegram bot.
    required: true
  api_method:
    type: str
    description:
      - Bot API method.
      - For reference, see U(https://core.telegram.org/bots/api).
    default: SendMessage
    version_added: 2.0.0
  api_args:
    type: dict
    description:
      - Any parameters for the method.
      - For reference to default method, V(SendMessage), see U(https://core.telegram.org/bots/api#sendmessage).
    version_added: 2.0.0
a[  
- name: Send notify to Telegram
  community.general.telegram:
    token: '9999999:XXXXXXXXXXXXXXXXXXXXXXX'
    api_args:
      chat_id: "000000"
      parse_mode: "markdown"
      text: "Your precious application has been deployed: https://example.com"
      disable_web_page_preview: true
      disable_notification: true

- name: Forward message to someone
  community.general.telegram:
    token: '9999999:XXXXXXXXXXXXXXXXXXXXXXX'
    api_method: forwardMessage
    api_args:
      chat_id: "000000"
      from_chat_id: 111111
      disable_notification: true
      message_id: '{{ saved_msg_id }}'
a  
msg:
  description: The message you attempted to send.
  returned: success
  type: str
  sample: "Ansible task finished"
telegram_error:
  description: Error message gotten from Telegram API.
  returned: failure
  type: str
  sample: "Bad Request: message text is empty"
N)AnsibleModule)quote)	fetch_urlc            
      j   t        t        t        ddd      t        d      t        dd            d	      } t        | j                  j	                  d
            }| j                  j	                  d      xs i }| j                  j	                  d      }|j	                  d      |d<   |j	                  d      |d<   |j	                  d      |d<   |d   dk(  r|d= dj                  ||      }| j                  r| j                  d       t        | |dt        j                  |      ddi      \  }}|d   dk(  r| j                  d       y |d   dk(  r| j                  d||       y t        j                  |d         }| j                  dj                  |d   ||       |d!   "       y )#NstrT)typerequiredno_logdict)r   SendMessage)r   default)tokenapi_args
api_method)argument_specsupports_check_moder   r   r   chat_id
parse_modetextplainz0https://api.telegram.org/bot{token}/{api_method})r   r   F)changedPOSTzContent-Typezapplication/json)methoddataheadersstatus   zFailed to send message)msginforesponsebodyzVFailed to send message, return status = {status}
url = {api_url}
api_args = {api_args})r   api_urlr   description)r"   telegram_error)r   r   r   paramsgetformat
check_mode	exit_jsonr   jsondumps	fail_jsonloads)moduler   r   r   urlr$   r#   r%   s           n/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/telegram.pymainr5   `   s   ED>v&>

 !F &--##G,-E}}  ,2H""<0J",,y1HY%\\,7H\||F+HV(\"
<
C
C%\f
C
gC'vs6

8@T(68J'KMNHdH~&	h2	5D8Tzz$v,'((.>3 )/ )  . 	 	
    __main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNr.   ansible.module_utils.basicr   +ansible.module_utils.six.moves.urllib.parser   ansible.module_utils.urlsr   r5   __name__ r6   r4   <module>rB      sQ    A @'R,
  4 = /*
Z zF r6   