예제 #1
0
def main():
    parse_command_line()

    # Create adapter.
    # See https://aka.ms/about-bot-adapter to learn more about how bots work.
    settings = BotFrameworkAdapterSettings(options.app_id,
                                           options.app_password)

    # Create MemoryStorage, UserState and ConversationState
    memory = MemoryStorage()
    user_state = UserState(memory)
    conversation_state = ConversationState(memory)

    # Create adapter.
    # See https://aka.ms/about-bot-adapter to learn more about how bots work.
    adapter = AdapterWithErrorHandler(settings, conversation_state)

    # Create dialogs and Bot
    recognizer = FlightBookingRecognizer(options)
    booking_dialog = BookingDialog()
    dialog = MainDialog(recognizer, booking_dialog)
    bot = DialogAndWelcomeBot(conversation_state, user_state, dialog)

    app = tornado.web.Application(
        [
            (r"/api/messages", MessageHandler, dict(adapter=adapter, bot=bot)),
        ],
        debug=options.debug,
    )
    app.listen(options.port)
    tornado.ioloop.IOLoop.current().start()
예제 #2
0
# Create the loop and Flask app
LOOP = asyncio.get_event_loop()
APP = Flask(__name__, instance_relative_config=True)
APP.config.from_object("config.DefaultConfig")

SETTINGS = BotFrameworkAdapterSettings(APP.config["APP_ID"], APP.config["APP_PASSWORD"])

# Create MemoryStorage, UserState and ConversationState
MEMORY = MemoryStorage()
USER_STATE = UserState(MEMORY)
CONVERSATION_STATE = ConversationState(MEMORY)

# Create adapter.
# See https://aka.ms/about-bot-adapter to learn more about how bots work.
ADAPTER = AdapterWithErrorHandler(SETTINGS, CONVERSATION_STATE)

# Create dialogs and Bot
RECOGNIZER = FlightBookingRecognizer(APP.config)
BOOKING_DIALOG = BookingDialog()
DIALOG = MainDialog(RECOGNIZER, BOOKING_DIALOG)
BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG)


# Listen for incoming requests on /api/messages.
@APP.route("/api/messages", methods=["POST"])
def messages():
    # Main bot message handler.
    if "application/json" in request.headers["Content-Type"]:
        body = request.json
    else:
예제 #3
0
SKILL_CONFIG = SkillConfiguration()

# Create MemoryStorage, UserState and ConversationState
MEMORY = MemoryStorage()
USER_STATE = UserState(MEMORY)
CONVERSATION_STATE = ConversationState(MEMORY)
ID_FACTORY = SkillConversationIdFactory(MEMORY)

CREDENTIAL_PROVIDER = SimpleCredentialProvider(CONFIG.APP_ID,
                                               CONFIG.APP_PASSWORD)
CLIENT = SkillHttpClient(CREDENTIAL_PROVIDER, ID_FACTORY)

# 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 = AdapterWithErrorHandler(SETTINGS, CONFIG, CONVERSATION_STATE, CLIENT,
                                  SKILL_CONFIG)

DIALOG = MainDialog(CONVERSATION_STATE, ID_FACTORY, CLIENT, SKILL_CONFIG,
                    CONFIG)

# Create the Bot
BOT = RootBot(CONVERSATION_STATE,
              DIALOG)  # , SKILL_CONFIG, ID_FACTORY, CLIENT, CONFIG)

AUTH_CONFIG = AuthenticationConfiguration(
    claims_validator=AllowedSkillsClaimsValidator(CONFIG).claims_validator)

SKILL_HANDLER = SkillHandler(ADAPTER, BOT, ID_FACTORY, CREDENTIAL_PROVIDER,
                             AUTH_CONFIG)

예제 #4
0
from botbuilder.schema import Activity

from config import DefaultConfig
from welcome import  WelcomeBot
from dialog import SmartBot

from adapter_with_error_handler import AdapterWithErrorHandler

CONFIG = DefaultConfig()
MEMORY = MemoryStorage()
USER_STATE = UserState(MEMORY)
CONVERSATION_STATE = ConversationState(MEMORY)

# Create adapter
botadaptersettings = BotFrameworkAdapterSettings(CONFIG.APP_ID, CONFIG.APP_PASSWORD)
botadapter = AdapterWithErrorHandler(botadaptersettings, CONVERSATION_STATE)

# Create dialogs and Bot
WELCOME = WelcomeBot()
BOT = SmartBot()

# 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 ""
예제 #5
0
from adapter_with_error_handler import AdapterWithErrorHandler
from bots import ChildBot
from dialogs import MainDialog
from config import DefaultConfig

CONFIG = DefaultConfig()

STORAGE = MemoryStorage()

CONVERSATION_STATE = ConversationState(STORAGE)
USER_STATE = UserState(STORAGE)

# 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 = AdapterWithErrorHandler(SETTINGS, CONVERSATION_STATE, USER_STATE)


# 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
예제 #6
0
    MemoryStorage,
    ConversationState,
)

CONFIG = DefaultConfig()
CLAIMS_VALIDATOR = AllowedCallersClaimsValidator(CONFIG)
AUTH_CONFIG = AuthenticationConfiguration(
    claims_validator=CLAIMS_VALIDATOR.claims_validator)
# Create adapter.
# See https://aka.ms/about-bot-adapter to learn more about how bots work.
SETTINGS = BotFrameworkAdapterSettings(
    app_id=CONFIG.APP_ID,
    app_password=CONFIG.APP_PASSWORD,
    auth_configuration=AUTH_CONFIG,
)
ADAPTER = AdapterWithErrorHandler(SETTINGS)

# Create the Bot
MEMORY = MemoryStorage()
CONVERSATION_STATE = ConversationState(MEMORY)
# Create the Bot
BOT = CoCoBot(CONVERSATION_STATE)


# 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)
예제 #7
0
relative_path = os.path.abspath(os.path.dirname(__file__))
path = os.path.join(relative_path, "config.yaml")
with open(path, "r") as ymlfile:
    cfg = yaml.safe_load(ymlfile)

PORT = cfg["Settings"]["Port"]
SETTINGS = BotFrameworkAdapterSettings(cfg["Settings"]["AppId"],
                                       cfg["Settings"]["AppPassword"])

# Create MemoryStorage, UserState and ConversationState
memory = MemoryStorage()

user_state = UserState(memory)
conversation_state = ConversationState(memory)

ADAPTER = AdapterWithErrorHandler(SETTINGS, conversation_state)
RECOGNIZER = FlightBookingRecognizer(cfg["Settings"])
BOOKING_DIALOG = BookingDialog()

dialog = MainDialog(RECOGNIZER, BOOKING_DIALOG)
bot = DialogAndWelcomeBot(conversation_state, user_state, dialog)


async def messages(req: web.Request) -> web.Response:
    body = await req.json()
    activity = Activity().deserialize(body)
    auth_header = req.headers[
        "Authorization"] if "Authorization" in req.headers else ""

    async def aux_func(turn_context):
        await bot.on_turn(turn_context)