Last active
February 17, 2021 15:09
-
-
Save saurabhkdm/39b492d0adc2d0de252aa8a15009cc12 to your computer and use it in GitHub Desktop.
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