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
49 lines (36 loc) · 1.37 KB
/
Copy pathapp.py
File metadata and controls
49 lines (36 loc) · 1.37 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
40
41
42
43
44
45
46
47
48
49
from flask import Flask,request,Response
from botbuilder.schema import Activity
from botbuilder.core import (
BotFrameworkAdapter,
BotFrameworkAdapterSettings,
ConversationState,
UserState,
MemoryStorage
)
import asyncio
from bot import StateBot
from botbuilder.azure import CosmosDbConfig,CosmosDbStorage
app = Flask(__name__)
loop = asyncio.get_event_loop()
botadaptersettings = BotFrameworkAdapterSettings("","")
botadapter = BotFrameworkAdapter(botadaptersettings)
memstore = MemoryStorage()
constate = ConversationState(memstore)
#userstate = UserState(memstore)
key = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
cosconfig = CosmosDbConfig("https://localhost:8081",key,"userprofile","userinfo")
cosdbStore = CosmosDbStorage(cosconfig)
sbot = StateBot(constate,cosdbStore)
@app.route("/api/messages",methods=["POST"])
def messages():
if "application/json" in request.headers["content-type"]:
jsonmessage = request.json
else:
return Response(status=415)
activity = Activity().deserialize(jsonmessage)
async def turn_call(turn_context):
await sbot.on_turn(turn_context)
task = loop.create_task(botadapter.process_activity(activity,"",turn_call))
loop.run_until_complete(task)
if __name__ == '__main__':
app.run('localhost',3978)