Created
September 10, 2022 04:39
-
-
Save ojmccall/beabd6d8388f018b855548f2e76cdad8 to your computer and use it in GitHub Desktop.
Slack Message Router
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 json | |
import functions_framework | |
import requests | |
from flask import Flask, request, jsonify | |
from datetime import timedelta | |
from google.cloud import storage | |
import datetime | |
# Register an HTTP function with the Functions Framework | |
@functions_framework.http | |
def input_request(request): | |
body = request.get_json("body") | |
date = str(datetime.datetime.utcnow()) | |
print(body) | |
strbody = str(body) | |
bucketname = "null bucket" | |
# this is for deployment 1 to confirm the URL with slack | |
""" | |
challenge_answer = body["challenge"] | |
return { | |
'statusCode': 200, | |
'body': challenge_answer | |
} | |
""" | |
if "create Data Extension" in strbody: | |
bucketname = "sfmc-de-sink" | |
if "file" in strbody: | |
bucket = bucketname | |
storage_client = storage.Client() | |
bucket = storage_client.get_bucket(bucket) | |
exportFileName = f"{date}_DE_Slack.json" | |
blob = bucket.blob(exportFileName) | |
blob.upload_from_string(str(body),content_type="application/json") | |
return { | |
'statusCode': 200, | |
'body': "OK" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment