我正在尝试将Microsoft Team BOT作为Azure Web应用程序运行-可以在此处找到完整的代码
application.py:
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import sys
import traceback
from datetime import datetime
from aiohttp import web
from aiohttp.abc import HTTPException
from aiohttp.web import Request, Response, json_response
from botbuilder.core import (BotFrameworkAdapterSettings, TurnContext, BotFrameworkAdapter, )
from botbuilder.core.integration import aiohttp_error_middleware
from botbuilder.schema import Activity, ActivityTypes
from bots import EchoBot
from config import DefaultConfig
CONFIG = DefaultConfig()
# Create adapter.
# See https://aka.ms/about-bot-adapter to learn more about how bots work.
SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, CONFIG.APP_PASSWORD)
ADAPTER = BotFrameworkAdapter(SETTINGS)
# Catch-all for errors.
async def on_error(context: TurnContext, error: Exception):
# This check writes out errors to console log .vs. app insights.
# NOTE: In production environment, you should consider logging this to Azure
# application insights.
print(f"\n [on_turn_error] unhandled error: {error}", file=sys.stderr)
traceback.print_exc()
# Send a message to the user
await context.send_activity("The bot encountered an error or bug.")
await context.send_activity(
"To continue to run this bot, please fix the bot source code."
)
# Send a trace activity if we're talking to the Bot Framework Emulator
if context.activity.channel_id == "emulator":
# Create a trace activity that contains the error object
trace_activity = Activity(
label="TurnError",
name="on_turn_error Trace",
timestamp=datetime.utcnow(),
type=ActivityTypes.trace,
value=f"{error}",
value_type="https://www.botframework.com/schemas/error",
)
# Send a trace activity, which will be displayed in Bot Framework Emulator
await context.send_activity(trace_activity)
ADAPTER.on_turn_error = on_error
# Create the Bot
BOT = EchoBot()
# Listen for incoming requests on /api/messages
async def messages(req: Request) -> Response:
# Main bot message handler.
if "application/json" in req.headers["Content-Type"]:
body = await req.json()
else:
return Response(status=415)
activity = Activity().deserialize(body)
auth_header = req.headers["Authorization"] if "Authorization" in req.headers else ""
response = await ADAPTER.process_activity(activity, auth_header, BOT.on_turn)
if response:
return json_response(data=response.body, status=response.status)
return Response(status=201)
APP = web.Application(middlewares=[aiohttp_error_middleware])
APP.router.add_post("/api/messages", messages)
if __name__ == "__main__":
try:
web.run_app(APP, host="localhost", port=CONFIG.PORT)
except Exception as error:
raise error
在本地运行时,我可以将端口设置为8000,例如,将ngrok指向localhost,并在我的bot通道注册中指定url,一切正常。我一直在努力让我的代码在Azure中工作,但我就是无法做到这一点。我已将脚本配置为在端口8000上运行,并在应用程序设置中设置参数(我尝试了端口和端口,因为我了解到有时其中一个标志不起作用:Azure上的应用程序设置)
但它在日志中仍然说:
站点leobot msbot的容器mycontainer已退出,站点启动失败错误-容器mycontainer未响应端口8000上的HTTP ping,站点启动失败。有关调试,请参阅容器日志。
我也尝试过十几个启动命令,但我就是搞不懂。编辑:找到https://docs.microsoft.com/en-us/azure/app-service/containers/how-to-configure-python并添加了“python3.7-maiohttp.web-hlocalhost-p8000应用程序:init_func”作为启动命令,并将代码更改为
def init_func(argv):
APP = web.Application(middlewares=[aiohttp_error_middleware])
APP.router.add_post("/api/messages", messages)
return APP
if __name__ == "__main__":
APP = init_func(None)
try:
web.run_app(APP, host="localhost", port=CONFIG.PORT)
except Exception as error:
raise error
然后在日志上写着-
也许有人有这方面的经验,可以帮助我:)
所以在努力设置我的机器人两天后,我终于找到了答案。借助这篇文章和微软的这篇文章。
在设置-配置下,我添加了启动命令
python3.7 -m aiohttp.web -H 0.0.0.0 -P 8000 application:init_func
重要的是不要使用localhost,而是使用0.0。0.0 !
在我的application.py文件中,我添加了一个init func,如前所述,并将代码更改为
def init_func(argv):
APP = web.Application(middlewares=[aiohttp_error_middleware])
APP.router.add_post("/api/messages", messages)
return APP
if __name__ == "__main__":
APP = init_func(None)
try:
web.run_app(APP, host="0.0.0.0", port=CONFIG.PORT)
except Exception as error:
raise error
目前,我正在尝试使用和来运行Spring Boot应用程序,在默认情况下作为web应用程序运行,在需要时作为独立的命令行应用程序运行(通过某种命令行参数)。我正在努力弄清楚当提供程序参数时,如何单独将其作为控制台应用程序运行。请给出任何建议。 主类-SpringApplication CommandLineRunner
问题内容: 我想将Java应用程序作为服务运行。不幸的是,我的局限性在于无法使用Java Service Wrapper之 类的工具(它确实是一种出色的工具)。 有什么方法可以在不依赖外部应用程序的情况下将可执行的JAR作为服务运行吗?我当前已安装该服务,但无法启动。这是我遇到的困扰,除了关于JSW的信息之外,我无法在Google上找到其他任何东西。 问题答案: 有Java Service Wra
我使用maven-archetype-webapp编写了一个核心java web应用程序,并尝试在基于azure windows的webapp中部署jar文件和web.config,但无法访问url。我的应用程序中只有主页。并遵循以下步骤。我可以在我的本地系统中运行它,并且可以看到主页。 azure-webapp-maven-plugin add in POM 和 build 与 mvn azur
问题内容: 我有一个现有的Flask应用程序,并且想找到通往另一个应用程序的路线。更具体地说,第二个应用程序是Plotly Dash应用程序。如何在现有的Flask应用程序中运行Dash应用程序? 我还尝试将路由添加到Dash实例,因为它是Flask应用程序,但出现错误: 问题答案: 从文档: 基本的Flask应用程序可从访问app.server。 你还可以将自己的Flask应用实例传递到Dash
我试图在SpringMVC中运行SpringBoot应用程序,在SpringMVCPOM中添加SpringBoot应用程序依赖项,并扫描SpringBoot包,但我面临以下问题
问题内容: 每当用户断开手机通话时,我都希望显示自定义弹出消息。问题是如何检测应用程序何时未运行。任何线索都将有所帮助。 问题答案: 已经有一段时间了,并且已经有了很多发展。 首先,如何在Flutter中创建服务以使应用程序始终在后台运行有一些答案? 此外,使用Flutter插件和地理围栏(在2018年9月),Flutter / Background流程 基本上将使您指向在后台执行中等/执行Dar