Google Chat - Send message

Octopus.Script exported 2024-04-03 by harrisonmeister belongs to ‘Google Chat’ category.

Send a message to a Google Chat space using a configured chat webhook.

Multi-line message content and basic formatting are supported.

Note: This script is written in python, and is required for this step to function correctly.

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Webhook URL

GoogleChat.SendMessage.WebhookUrl =

Provide the Google Chat Webhook URL

Message Content

GoogleChat.SendMessage.MessageContent =

Provide the message to send. Multi-line values, and basic formatting are supported.

Script body

Steps based on this template will execute the following Python script.

import subprocess
import sys

subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'httplib2', '--disable-pip-version-check'])

# parameters
webhook_url = get_octopusvariable("GoogleChat.SendMessage.WebhookUrl")
message_content = get_octopusvariable("GoogleChat.SendMessage.MessageContent")

if not webhook_url:
  raise ValueError('Webhook url null or empty!')
  
if not message_content:
  raise ValueError('Message content null or empty!')
  
from json import dumps
from httplib2 import Http

app_message = {"text": message_content}
message_headers = {"Content-Type": "application/json; charset=UTF-8"}
http_obj = Http()
response = http_obj.request(
  uri=webhook_url,
  method="POST",
  headers=message_headers,
  body=dumps(app_message),
)
printverbose('Google response:')
printverbose(response)

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "6c4c6253-45de-404f-b725-c96e1d7e4958",
  "Name": "Google Chat - Send message",
  "Description": "Send a message to a [Google Chat](https://chat.google.com) space using a configured [chat webhook](https://developers.google.com/workspace/chat/quickstart/webhooks#python_2).\n\nMulti-line message content and [basic formatting](https://developers.google.com/workspace/chat/format-messages) are supported.\n\n**Note:** This script is written in python, and is required for this step to function correctly.",
  "Version": 1,
  "ExportedAt": "2024-04-03T13:02:57.192Z",
  "ActionType": "Octopus.Script",
  "Author": "harrisonmeister",
  "Packages": [],
  "Parameters": [
    {
      "Id": "bb5767eb-bbfb-4379-917e-31f73cf56ad2",
      "Name": "GoogleChat.SendMessage.WebhookUrl",
      "Label": "Webhook URL",
      "HelpText": "Provide the Google Chat [Webhook URL](https://developers.google.com/workspace/chat/quickstart/webhooks)",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "Sensitive"
      }
    },
    {
      "Id": "cb6577d7-d160-4e3a-86ea-b536bf92133a",
      "Name": "GoogleChat.SendMessage.MessageContent",
      "Label": "Message Content",
      "HelpText": "Provide the message to send. Multi-line values, and [basic formatting](https://developers.google.com/workspace/chat/format-messages) are supported.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "MultiLineText"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.Syntax": "Python",
    "Octopus.Action.Script.ScriptBody": "import subprocess\nimport sys\n\nsubprocess.check_call([sys.executable, '-m', 'pip', 'install', 'httplib2', '--disable-pip-version-check'])\n\n# parameters\nwebhook_url = get_octopusvariable(\"GoogleChat.SendMessage.WebhookUrl\")\nmessage_content = get_octopusvariable(\"GoogleChat.SendMessage.MessageContent\")\n\nif not webhook_url:\n  raise ValueError('Webhook url null or empty!')\n  \nif not message_content:\n  raise ValueError('Message content null or empty!')\n  \nfrom json import dumps\nfrom httplib2 import Http\n\napp_message = {\"text\": message_content}\nmessage_headers = {\"Content-Type\": \"application/json; charset=UTF-8\"}\nhttp_obj = Http()\nresponse = http_obj.request(\n  uri=webhook_url,\n  method=\"POST\",\n  headers=message_headers,\n  body=dumps(app_message),\n)\nprintverbose('Google response:')\nprintverbose(response)"
  },
  "Category": "Google Chat",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/google-chat-send-message.json",
  "Website": "/step-templates/6c4c6253-45de-404f-b725-c96e1d7e4958",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADOCAYAAAB7AU2DAAAAxHpUWHRSYXcgcHJvZmlsZSB0eXBlIGV4aWYAAHjabVBbDgMhCPz3FD2CPGTxOO6jSW/Q4xcFm91uJ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wIj4KICAgPHhtcE1NOkhpc3Rvcnk+CiAgICA8cmRmOlNlcT4KICAgICA8cmRmOmxpCiAgICAgIHN0RXZ0OmFjdGlvbj0ic2F2ZWQiCiAgICAgIHN0RXZ0OmNoYW5nZWQ9Ii8iCiAgICAgIHN0RXZ0Omluc3RhbmNlSUQ9InhtcC5paWQ6NjI5MjdkOWUtOTI1OS00MmNkLTgzYTMtYjg5OTYxZmE2MjBhIgogICAgICBzdEV2dDpzb2Z0d2FyZUFnZW50PSJHaW1wIDIuMTAgKExpbnV4KSIKICAgICAgc3RFdnQ6d2hlbj0iMjAyNC0wNC0wMlQxNjoxNTo0NyswMTowMCIvPgogICAgPC9yZGY6U2VxPgogICA8L3htcE1NOkhpc3Rvcnk+CiAgPC9yZGY6RGVzY3JpcHRpb24+CiA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgCjw/eHBhY2tldCBlbmQ9InciPz5CU53FAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH6AQCDw8vTl87rwAACdxJREFUeNrt3V2MXGUdgPHnPTPbUkBpaQutgEUCggVUYGdRVCw7W4pRY9rtlhJiTDS2kJV+gJfYG9GoMdGopa0i0RgToZ+0u203FBMELwwJRFBMWjHBC3Fnqiaiod2dmdeLbm1pZ7a7tLN7zuzzS3rR3e3CnHOe+Z/3zFdgrFYfvILI1cB1wFzgQmD6Gf5VDsif4WfyIz83mjYg1PvGldPfnP5s11eT91zw3BEgolSovTnjgiO/nb/hou8efDnLt2P0g3f1oQuJ8V7g80SuB2am7QZUajnakqpHZMrEWhtDr7x74WBX4a5LD7zwl6zejqTuV7/454RVB7uJ8SVgM/CxNMahlEcSuSZE+kud7e9rnUBWH5xBvrYReAK42t2ss3QdIewtdxauzH4gqw6dT+QJ4L4xrAukMUcSA33lYseV2Q2k9085iD8BPputmxAard+VLtdH4r5ysWNBNgMZzt0HrHQ/6twtQupMEmJ/uauwIFuBfPnQFcAjD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IcFjLiv2uOQxkIk+xjh4/ANM9OZLcg04OA5mEQNI+OcJGkvw6lvk4h4FMSiC5NMfxKEluPcv6vVplIJNkei6mMo7ARnKJcWR9iZv9CRLSFwdsJFbXsXTANYcTxEBOj6P2IMsPGIeBpEDlreMHZkriqKyj52kX5AaSEuelYpF+YnL0POPkcA1i46fE8SNidT09nlY5QVJ3ipWf/DiqPGQcBmIgp8fxQ2Lbg9ztU9YNJK2mDcVJiuNRKjxET5+PcxhIirUNT04csbaelQPG4SI95YZyxw/aiYpjE7Gy1qtVTpBsmLgXTEUImwisNw4DyY4YJigONpHLr6F7wFcCGkiGnP/fiYhjC0mynqV9Tg4DyZhqvtlxbKYSHmCZryE3kEwGkmtmHI8de/eR/V6tMpCMOtp2/GA+93FUQy8r9vkgoIFk2FvnNSOOnxLp5W7fYMFAMn8Lquc6jseI9PqOh2qNQL6wK9L4YxPGG8fjhFovPV7KVasEMnKidc7i6PbFTmq9QN446zgq+fvpfvqoh4RaMZBXzyKOn1PL9bKy38mhlg2k/x2sQyLwM2JYzYq9Tg61cCCBF4FfjjOOXxC4n579Lsg1yqHVKrYtmQP0AbeOIY4tJLV1LHPNoalxigXLBw4DdwGP0/iq1iDwAEMzeo1DU2uC/H+SLAowbSGETwE3A7M49jHAzwG7WT7whrtdY/U/dpW4anbr6sEAAAAASUVORK5CYII=",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Wednesday, April 3, 2024