forked from rvinothrajendran/BotTutorialSample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
39 lines (27 loc) · 1.1 KB
/
Copy pathapp.py
File metadata and controls
39 lines (27 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from flask import Flask,request,Response
from botbuilder.core import BotFrameworkAdapter,BotFrameworkAdapterSettings,TurnContext,ConversationState,MemoryStorage
from botbuilder.schema import Activity
import asyncio
from animationcard import SampleAnimationCard
app = Flask(__name__)
loop = asyncio.get_event_loop()
botsettings = BotFrameworkAdapterSettings("","")
botadapter = BotFrameworkAdapter(botsettings)
CONMEMORY = ConversationState(MemoryStorage())
botdialog = SampleAnimationCard()
@app.route("/api/messages",methods=["POST"])
def messages():
if "application/json" in request.headers["content-type"]:
body = request.json
else:
return Response(status = 415)
activity = Activity().deserialize(body)
auth_header = (request.headers["Authorization"] if "Authorization" in request.headers else "")
async def call_fun(turncontext):
await botdialog.on_turn(turncontext)
task = loop.create_task(
botadapter.process_activity(activity,auth_header,call_fun)
)
loop.run_until_complete(task)
if __name__ == '__main__':
app.run('localhost',3978)