Skip to content

Commit

Permalink
Merge pull request #3 from tkamppi/push-json-pubsub
Browse files Browse the repository at this point in the history
Push JSON serialized string to Pub/Sub
  • Loading branch information
tkamppi authored Sep 18, 2019
2 parents edb0254 + e5fb976 commit 3f55c5e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/dialog_submission/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def dialog_submission(request):
if payload:
json_payload = json.loads(payload)
if json_payload.get("type") == "dialog_submission":
pubsub_push(payload)
pubsub_push(json_payload)
return ""

return "Unhandled Slack request received", 403
Expand Down Expand Up @@ -66,10 +66,11 @@ def __verify_signature(request):
def pubsub_push(data):
"""
Takes the data sent in, and pushes it into a Pub/Sub topic.
:param data: object which implements __str__ method.
:param data: object serializable to JSON using json.dumps(data).
"""
topic_name = os.environ.get("PUBSUB_TOPIC_NAME")
pubsub_bytestring = str(data).encode("utf-8") # Pub/Sub requires bytestring
json_str = json.dumps(data)
pubsub_bytestring = str(json_str).encode("utf-8") # Pub/Sub requires bytestring

publisher = pubsub_v1.PublisherClient()
publisher.publish(topic_name, pubsub_bytestring, caller="Slack")

0 comments on commit 3f55c5e

Please sign in to comment.