This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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