1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-07-05 10:08:58 +00:00

telegram: add ability to specify a custom URL for the API (#12040)

* feat: Custom telegram api host

* fix: default param  telegram api host

* fix:  default api_host for DOCUMENTATION

* fix: Documentation and example

* changelog: add bugfix fragment for telegram api_host

* fix:  use [] for module.params access
This commit is contained in:
Bronislav 2026-05-16 01:30:13 +04:00 committed by GitHub
parent 2f96093dbf
commit 47a19fad1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 4 deletions

View file

@ -32,6 +32,12 @@ options:
description:
- Token identifying your telegram bot.
required: true
api_host:
type: str
description:
- Custom telegram API host.
default: api.telegram.org
version_added: 13.0.0
api_method:
type: str
description:
@ -67,6 +73,17 @@ EXAMPLES = r"""
from_chat_id: 111111
disable_notification: true
message_id: '{{ saved_msg_id }}'
- name: Send notify to custom telegram API host
community.general.telegram:
token: '9999999:XXXXXXXXXXXXXXXXXXXXXXX'
api_host: "telegram.example.com"
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
"""
RETURN = r"""
@ -95,15 +112,17 @@ def main():
module = AnsibleModule(
argument_spec=dict(
token=dict(type="str", required=True, no_log=True),
api_host=dict(type="str", default="api.telegram.org"),
api_args=dict(type="dict"),
api_method=dict(type="str", default="SendMessage"),
),
supports_check_mode=True,
)
token = quote(module.params.get("token"))
api_args = module.params.get("api_args") or {}
api_method = module.params.get("api_method")
token = quote(module.params["token"])
api_host = module.params["api_host"]
api_args = module.params["api_args"] or {}
api_method = module.params["api_method"]
# filling backward compatibility args
api_args["chat_id"] = api_args.get("chat_id")
api_args["parse_mode"] = api_args.get("parse_mode")
@ -112,7 +131,7 @@ def main():
if api_args["parse_mode"] == "plain":
del api_args["parse_mode"]
url = f"https://api.telegram.org/bot{token}/{api_method}"
url = f"https://{api_host}/bot{token}/{api_method}"
if module.check_mode:
module.exit_json(changed=False)