Skip to content

Instantly share code, notes, and snippets.

@akkefa
Created January 26, 2018 04:43
Show Gist options
  • Save akkefa/1f8c9589f5eec56d23871ead04461ac1 to your computer and use it in GitHub Desktop.
Save akkefa/1f8c9589f5eec56d23871ead04461ac1 to your computer and use it in GitHub Desktop.
from flask.views import MethodView
from flask import jsonify, request, abort, make_response, current_app
from flask_jwt_extended import jwt_required
from agent import Agent
from web.extensions import csrf
from web.blueprints.data.models import Utterance
class SlackAPI(MethodView):
"""
Web hook api
"""
decorators = [csrf.exempt]
def __init__(self):
"""Validate the request data"""
token = request.values.get('token')
active_client = None
for client in payload_tokens:
if client['token'] == token:
active_client = client
if active_client is None:
abort(make_response(jsonify({"error": "token is "
"missing/incorrect!"}), 400))
if request.values.get('bot_name'):
abort(make_response(jsonify({"error": "Bot is "
"not allowed"}), 400))
if request.values.get('user_name') == 'slackbot':
abort(make_response(jsonify({"error": "Bot is "
"not allowed"}), 400))
self.request_params = {
'channel_name': request.values.get('channel_name'),
'text': request.values.get('text'),
'user_name': request.values.get('user_name'),
'url': active_client['url']
}
def post(self):
"""Post request"""
from web.blueprints.webhook.tasks import send_massage_to_slack
send_massage_to_slack.delay(
request_params_dict=self.request_params)
return jsonify({'success': True}), 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment