Skip to content

Instantly share code, notes, and snippets.

@saurabhkdm
Last active February 17, 2021 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saurabhkdm/39b492d0adc2d0de252aa8a15009cc12 to your computer and use it in GitHub Desktop.
Save saurabhkdm/39b492d0adc2d0de252aa8a15009cc12 to your computer and use it in GitHub Desktop.
import base64
from json import dumps
from httplib2 import Http
def hello_pubsub(event, context):
"""Triggered from a message on a Cloud Pub/Sub topic.
Args:
event (dict): Event payload.
context (google.cloud.functions.Context): Metadata for the event.
"""
pubsub_message = base64.b64decode(event["data"]).decode("utf-8")
url = "Chat-Channel"
bot_message = {"text": pubsub_message}
message_headers = {"Content-Type": "application/json; charset=UTF-8"}
http_obj = Http()
response = http_obj.request(
uri=url,
method="POST",
headers=message_headers,
body=dumps(bot_message),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment