PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /proc/self/root/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
IP: 209.182.202.254
Choose File :

Url:
Dir : //proc/self/root/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/google_chat.py

"""
Module for sending messages to google chat.

.. versionadded:: 2019.2.0

To use this module you need to configure a webhook in the google chat room
where you would like the message to be sent, see:

    https://developers.google.com/hangouts/chat/how-tos/webhooks
"""

import json

# ------------------------------------------------------------------------------
# module properties
# ------------------------------------------------------------------------------

__virtualname__ = "google_chat"

# ------------------------------------------------------------------------------
# property functions
# ------------------------------------------------------------------------------


def __virtual__():
    return __virtualname__


# ------------------------------------------------------------------------------
# callable functions
# ------------------------------------------------------------------------------


def send_message(url, message):
    """
    Send a message to the google chat room specified in the webhook url.

    .. code-block:: bash

        salt '*' google_chat.send_message "https://chat.googleapis.com/v1/spaces/example_space/messages?key=example_key" "This is a test message"
    """
    headers = {"Content-Type": "application/json"}
    data = {"text": message}
    result = __utils__["http.query"](
        url,
        "POST",
        data=json.dumps(data),
        header_dict=headers,
        decode=True,
        status=True,
    )

    if result.get("status", 0) == 200:
        return True
    else:
        return False