Created
April 30, 2021 02:35
-
-
Save alanwsmith/a908202622af3ec3bfd8f3148af6179c to your computer and use it in GitHub Desktop.
Basic Twitch EventSub Server Example
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 os | |
from flask import Flask, request, Response | |
app = Flask(__name__) | |
@app.route('/webhooks/twitch-callback', methods=['POST']) | |
def respond(): | |
json_body = request.data.decode('utf-8') | |
json_data = json.loads(json_body) | |
print(json_data) | |
if 'challenge' in json_data: | |
print("returning challenge") | |
return Response( | |
status=200, | |
response=json_data['challenge'] | |
) | |
else: | |
follower = json_data['event']['user_name'] | |
os.system(""" | |
osascript -e 'display notification "Welcome {}!" with title "NEW FOLLOWER"' | |
""".format(follower)) | |
print(f'Welcomed new follower: {follower}') | |
return Response( | |
status=200 | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment