-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
45 lines (33 loc) · 1.4 KB
/
Copy pathapp.py
File metadata and controls
45 lines (33 loc) · 1.4 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
from flask import Flask, request, Response
from botbuilder.core import BotFrameworkAdapter, BotFrameworkAdapterSettings, ConversationState,MemoryStorage
from botbuilder.schema import Activity
import asyncio
from luis.luisApp import LuisConnect
import os
from logger.logger import Log
app = Flask(__name__)
loop = asyncio.get_event_loop()
bot_settings = BotFrameworkAdapterSettings("", "")
bot_adapter = BotFrameworkAdapter(bot_settings)
#CON_MEMORY = ConversationState(MemoryStorage())
luis_bot_dialog = LuisConnect()
@app.route("/api/messages", methods=["POST"])
def messages():
if "application/json" in request.headers["content-type"]:
log=Log()
request_body = request.json
user_says = Activity().deserialize(request_body)
log.write_log(sessionID='session1',log_message="user says: "+str(user_says))
authorization_header = (request.headers["Authorization"] if "Authorization" in request.headers else "")
async def call_user_fun(turncontext):
await luis_bot_dialog.on_turn(turncontext)
task = loop.create_task(
bot_adapter.process_activity(user_says, authorization_header, call_user_fun)
)
loop.run_until_complete(task)
return ""
else:
return Response(status=406) # status for Not Acceptable
if __name__ == '__main__':
#app.run(port= 3978)
app.run()