Skip to content

Instantly share code, notes, and snippets.

@alanwsmith
Created April 30, 2021 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanwsmith/a908202622af3ec3bfd8f3148af6179c to your computer and use it in GitHub Desktop.
Save alanwsmith/a908202622af3ec3bfd8f3148af6179c to your computer and use it in GitHub Desktop.
Basic Twitch EventSub Server Example
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