-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add embeded message to notifications youtube videos
- Add the method to send notifications when the event is received by the Youtube server - Create prettify embed to send notifications message in guilds subscribed - Change youtube webhook api route to get the new video infos and pass to service to send new video notifications messages
- Loading branch information
Showing
2 changed files
with
98 additions
and
5 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
import re | ||
|
||
from flask import request | ||
|
||
from app import logger | ||
from app.constants import LogTypes as logconstants | ||
from app.webhooks import webhooks | ||
|
||
pattern_video_id = r'<yt:videoId>(.*?)</yt:videoId>' | ||
pattern_channel_id = r'<yt:channelId>(.*?)</yt:channelId>' | ||
|
||
@webhooks.route('/youtube', methods=['GET', 'POST']) | ||
def youtube_webhook(): | ||
# from app import bot | ||
|
||
challenge = request.args.get('hub.challenge') | ||
|
||
if (challenge): | ||
if challenge: | ||
return challenge | ||
|
||
logger.info(f'Received Youtube webhook: {request.data}', log_type=logconstants.COMMAND_INFO_TYPE) | ||
data = request.data.decode('utf-8') | ||
|
||
logger.info(f'Received Youtube webhook: {data}', log_type=logconstants.COMMAND_INFO_TYPE) | ||
|
||
match_video_id = re.search(pattern_video_id, data) | ||
match_channel_id = re.search(pattern_channel_id, data) | ||
|
||
if not match_video_id or not match_channel_id: | ||
logger.error('Invalid Youtube webhook data', log_type=logconstants.COMMAND_INFO_TYPE) | ||
return 'Invalid request data', 403 | ||
|
||
from app.services.notifications_youtube_video import send_youtube_video_notification | ||
|
||
logger.info(f'Video ID: {match_video_id}, Channel ID: {match_channel_id}') | ||
|
||
send_youtube_video_notification(match_video_id, match_channel_id) | ||
|
||
return 'Processed', 204 | ||
return 'Webhook processed', 204 |