Skip to content

Instantly share code, notes, and snippets.

@macdiesel
Created October 25, 2016 15:33
Show Gist options
  • Save macdiesel/7102e1bb1c434d34689bc3e2eb62e8b5 to your computer and use it in GitHub Desktop.
Save macdiesel/7102e1bb1c434d34689bc3e2eb62e8b5 to your computer and use it in GitHub Desktop.
import os
import sys
import requests
import click
HIPCHAT_API_URL = "http://api.hipchat.com"
NOTIFICATION_POST = "/v2/room/{}/notification"
AUTH_HEADER = "Authorization: Bearer {}"
def send_hipchat_message(auth_token_env_var, channel, message):
"""
Post a message to a HipChat channel.
"""
headers = {
"Authorization": "Bearer {}".format(os.environ[auth_token_env_var])
}
msg_payload = {
"color": "green",
"message": message,
"notify": False,
"message_format": "text"
}
post_url = HIPCHAT_API_URL + NOTIFICATION_POST.format(channel)
r = requests.post(post_url, headers=headers, json=msg_payload)
return r.status_code in (200, 201, 204)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment