community.general.telegram (2.5.9) — module

module for sending notifications via telegram

Authors: Artem Feofanov (@tyouxa), Nikolai Lomov (@lomserman)

Install collection

Install with ansible-galaxy collection install community.general:==2.5.9


Add to requirements.yml

  collections:
    - name: community.general
      version: 2.5.9

Description

Send notifications via telegram bot, to a verified group or user.

Also, the user may try to use any other telegram bot API method, if you specify I(api_method) argument.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

- 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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 }}'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Send a message to chat in playbook (deprecated old style)
  community.general.telegram:
    token: '9999999:XXXXXXXXXXXXXXXXXXXXXXX'
    chat_id: 000000
    msg: Ansible task finished

Inputs

    
msg:
    description:
    - (Deprecated) What message you wish to send.
    type: str

token:
    description:
    - Token identifying your telegram bot.
    required: true
    type: str

chat_id:
    description:
    - (Deprecated) Telegram group or user chat_id.
    type: str

api_args:
    description:
    - Any parameters for the method.
    - For reference to default method, C(SendMessage), see U(https://core.telegram.org/bots/api#sendmessage).
    type: dict
    version_added: 2.0.0
    version_added_collection: community.general

api_method:
    default: SendMessage
    description:
    - Bot API method.
    - For reference, see U(https://core.telegram.org/bots/api).
    type: str
    version_added: 2.0.0
    version_added_collection: community.general

msg_format:
    choices:
    - plain
    - markdown
    - MarkdownV2
    - html
    default: plain
    description:
    - (Deprecated) Message format. Formatting options C(markdown), C(MarkdownV2), and
      C(html) described in Telegram API docs (https://core.telegram.org/bots/api#formatting-options).
      If option C(plain) set, message will not be formatted.
    type: str

Outputs

msg:
  description: The message you attempted to send
  returned: success
  sample: Ansible task finished
  type: str
telegram_error:
  description: Error message gotten from Telegram API
  returned: failure
  sample: 'Bad Request: message text is empty'
  type: str