示例#1
0
class BotConfig(AppConfig):
    """ Bot initialization """
    name = 'bots'
    appConfig = config.DefaultConfig

    SETTINGS = BotFrameworkAdapterSettings(appConfig.APP_ID, appConfig.APP_PASSWORD)
    ADAPTER = BotFrameworkAdapter(SETTINGS)
    LOOP = asyncio.get_event_loop()

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

    dialog = MainDialog(appConfig)
    bot = DialogAndWelcomeBot(conversation_state, user_state, dialog)

    async def on_error(self, context: TurnContext, error: Exception):
        """
        Catch-all for errors.
        This check writes out errors to console log
        NOTE: In production environment, you should consider logging this to Azure
        application insights.
        """
        print(f'\n [on_turn_error]: { error }', file=sys.stderr)
        # Send a message to the user
        await context.send_activity('Oops. Something went wrong!')
        # Clear out state
        await self.conversation_state.delete(context)

    def ready(self):
        self.ADAPTER.on_turn_error = self.on_error
示例#2
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()
示例#3
0
from bots import DialogAndWelcomeBot
from helpers.dialog_helper import DialogHelper

APP_ID = ''
APP_PASSWORD = ''
PORT = 9000
SETTINGS = BotFrameworkAdapterSettings(APP_ID, APP_PASSWORD)
ADAPTER = BotFrameworkAdapter(SETTINGS)

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

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

dialog = MainDialog({})
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 ''
    try:
        return await ADAPTER.process_activity(
            activity, auth_header,
            lambda turn_context: await bot.on_turn(turn_context))
    except Exception as e:
        raise e
# Set the error handler on the Adapter.
# In this case, we want an unbound method, so MethodType is not needed.
ADAPTER.on_turn_error = on_error

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

# Create telemetry client
INSTRUMENTATION_KEY = app.config["APPINSIGHTS_INSTRUMENTATION_KEY"]
TELEMETRY_CLIENT = ApplicationInsightsTelemetryClient(INSTRUMENTATION_KEY)

# Create dialog and Bot
DIALOG = MainDialog(app.config, telemetry_client=TELEMETRY_CLIENT)
BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG,
                          TELEMETRY_CLIENT)


# 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:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = (request.headers["Authorization"]
示例#5
0
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)


# Listen for incoming requests on /api/messages
async def messages(req: Request) -> Response:
    # Main bot message handler.
示例#6
0
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)
ADAPTER = AdapterWithErrorHandler(SETTINGS, CONVERSATION_STATE)
RECOGNIZER = ConnectivityCheckRecognizer(APP.config)
CONNECTIVITY_DIALOG = ConnectivityCheckDialog()
IP_CHECK_DIALOG = IpCheckDialog()

DIALOG = MainDialog(RECOGNIZER, CONNECTIVITY_DIALOG, IP_CHECK_DIALOG)
BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG)


@APP.route("/api/messages", methods=["POST"])
def messages():
    """Main bot message handler."""
    if request.headers["Content-Type"] == "application/json":
        body = request.json
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = (
        request.headers["Authorization"] if "Authorization" in request.headers else ""
    )
示例#7
0
with open(path, 'r') as ymlfile:
    cfg = yaml.safe_load(ymlfile)

PORT = cfg['Settings']['Port']
SETTINGS = BotFrameworkAdapterSettings(cfg['Settings']['AppId'],
                                       cfg['Settings']['AppPassword'])
ADAPTER = BotFrameworkAdapter(SETTINGS)

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

# Commented out user_state because it's not being used.
user_state = UserState(memory)
conversation_state = ConversationState(memory)

dialog = MainDialog()
bot = RichCardsBot(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)

    try:
        await ADAPTER.process_activity(activity, auth_header, aux_func)
        return web.Response(status=200)
示例#8
0
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'])
ADAPTER = BotFrameworkAdapter(SETTINGS)

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

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

dialog = MainDialog(app.config)
bot = DialogAndWelcomeBot(conversation_state, user_state, dialog)


@app.route('/api/messages', methods=['POST'])
def messages():

    if request.headers['Content-Type'] == 'application/json':
        body = request.json
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = request.headers[
        'Authorization'] if 'Authorization' in request.headers else ''
# 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 = ShoppingRecognizer(CONFIG)
RECOMMEND_DIALOG = RecommendDialog()
ADJUST_DIALOG = AdjustDialog()

DIALOG = MainDialog(RECOGNIZER, RECOMMEND_DIALOG, ADJUST_DIALOG)
BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG)


# 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 ""
示例#10
0
    print(f'\n [on_turn_error]: { error }', file=sys.stderr)
    # Send a message to the user
    await context.send_activity('Oops. Something went wrong!')
    # Clear out state
    await conversation_state.delete(context)


ADAPTER.on_turn_error = on_error

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

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

dialog = MainDialog(cfg['Settings'])
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)

    try:
        await ADAPTER.process_activity(activity, auth_header, aux_func)
        return web.Response(status=200)
示例#11
0
SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, 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 = OrderingRecognizer(CONFIG)
OrderTracking_Dialog = OrderTrackingDialog(RECOGNIZER)
OrderStatus_Dialog = OrderStatusDialog(RECOGNIZER)
DIALOG = MainDialog(RECOGNIZER, OrderStatus_Dialog, OrderTracking_Dialog)
BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG)


# 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=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)

    activity = Activity().deserialize(body)
    auth_header = req.headers[
        "Authorization"] if "Authorization" in req.headers else ""
示例#12
0
# 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(CONFIG)
BOOKING_DIALOG = BookingDialog()
CANCEL_BOOKING_DIALOG = CancelBookingDialog()
EDIT_BOOKING_DIALOG = EditBookingDialog()
DIALOG = MainDialog(RECOGNIZER, BOOKING_DIALOG, CANCEL_BOOKING_DIALOG,
                    EDIT_BOOKING_DIALOG)
BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG)


# 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=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)

    activity = Activity().deserialize(body)
    auth_header = req.headers[
        "Authorization"] if "Authorization" in req.headers else ""
示例#13
0
# See https://aka.ms/about-bot-adapter to learn more about how bots work.
SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, 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 = AreaRecognizer(CONFIG)
AREA_DIALOG = AreaDialog()
DIALOG = MainDialog(RECOGNIZER, AREA_DIALOG)
BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG)


# 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)
示例#14
0
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)
ADAPTER = AdapterWithErrorHandler(SETTINGS, CONVERSATION_STATE)
RECOGNIZER = WorkBoardRecognizer(APP.config)
SHOWOKR_DIALOG = ShowOKRDialog(RECOGNIZER)
UPDATE_OKR_DIALOG = UpdateOKRDialog(RECOGNIZER)

DIALOG = MainDialog(RECOGNIZER, SHOWOKR_DIALOG, UPDATE_OKR_DIALOG)
BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG)


@APP.route("/api/messages", methods=["POST"])
def messages():
    """Main bot message handler."""
    if request.headers["Content-Type"] == "application/json":
        body = request.json

        print('body is ', body)
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = (request.headers["Authorization"]
示例#15
0
            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 MemoryStorage and state
MEMORY = MemoryStorage()
USER_STATE = UserState(MEMORY)
CONVERSATION_STATE = ConversationState(MEMORY)

# Create dialog
DIALOG = MainDialog(app.config["CONNECTION_NAME"])

# Create Bot
BOT = AuthBot(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:
        return Response(status=415)

    activity = Activity().deserialize(body)
示例#16
0
from dialogs import MainDialog
from bots import DialogAndWelcomeBot

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"])
ADAPTER = BotFrameworkAdapter(SETTINGS)

# Create MemoryStorage, UserState and ConversationState
MEMORY = MemoryStorage()
USER_STATE = UserState(MEMORY)
CONVERSATION_STATE = ConversationState(MEMORY)
DIALOG = MainDialog(APP.config)
BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG)


@APP.route("/api/messages", methods=["POST"])
def messages():
    """Main bot message handler."""
    if request.headers["Content-Type"] == "application/json":
        body = request.json
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = (request.headers["Authorization"]
                   if "Authorization" in request.headers else "")
示例#17
0
SETTINGS = BotFrameworkAdapterSettings(CONFIG.APP_ID, CONFIG.APP_PASSWORD)
#ADAPTER = BotFrameworkAdapter(SETTINGS)

# 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 = BotRecognizer(CONFIG)
FINDBOOK_DIALOG = FindBookDialog()
DIALOG = MainDialog(CONFIG.CONNECTION_NAME, RECOGNIZER, CONVERSATION_STATE)
BOT = DialogBot(CONVERSATION_STATE, USER_STATE, DIALOG)


# 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=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)

    activity = Activity().deserialize(body)
    auth_header = req.headers[
        "Authorization"] if "Authorization" in req.headers else ""
示例#18
0
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)

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

RECOGNIZER = InsuranceQueryRecognizer(CONFIG)
INSURANCE_RENEWAL_DIALOG = InsuranceRenewalDialog()
RESERVATION_BOOKING_DIALOG = ReservationBookingDialog()
MAIN_DIALOG = MainDialog(USER_STATE, RECOGNIZER, INSURANCE_RENEWAL_DIALOG,
                         RESERVATION_BOOKING_DIALOG)
BOT = InsuranceBot(CONVERSATION_STATE, USER_STATE, MAIN_DIALOG)


# 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.")
示例#19
0
    # Clear out state
    await CONVERSATION_STATE.delete(context)


# Set the error handler on the Adapter.
# In this case, we want an unbound function, so MethodType is not needed.
ADAPTER.on_turn_error = on_error

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

# Create Dialog and Bot
DIALOG = MainDialog(USER_STATE)
BOT = DialogBot(CONVERSATION_STATE, USER_STATE, DIALOG)


# 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)
示例#20
0
    # Clear out state
    await conversation_state.delete(context)
    raise error


ADAPTER.on_turn_error = on_error

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

# Commented out user_state because it's not being used.
user_state = UserState(memory)
conversation_state = ConversationState(memory)

# TODO add connection name
dialog = MainDialog(cfg['Settings']['ConnectionName'])
bot = AuthBot(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)

    try:
        await ADAPTER.process_activity(activity, auth_header, aux_func)
        return web.Response(status=200)
示例#21
0
# Create telemetry client.
# Note the small 'client_queue_size'.  This is for demonstration purposes.  Larger queue sizes
# result in fewer calls to ApplicationInsights, improving bot performance at the expense of
# less frequent updates.
INSTRUMENTATION_KEY = CONFIG.APPINSIGHTS_INSTRUMENTATION_KEY
TELEMETRY_CLIENT = ApplicationInsightsTelemetryClient(
    INSTRUMENTATION_KEY,
    telemetry_processor=AiohttpTelemetryProcessor(),
    client_queue_size=10)

# Create dialogs and Bot
RECOGNIZER = FlightBookingRecognizer(CONFIG)
BOOKING_DIALOG = BookingDialog()
DIALOG = MainDialog(RECOGNIZER,
                    BOOKING_DIALOG,
                    telemetry_client=TELEMETRY_CLIENT)
BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG,
                          TELEMETRY_CLIENT)


# 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=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)

    activity = Activity().deserialize(body)
    auth_header = req.headers[
示例#22
0
            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 MemoryStorage and state
MEMORY = MemoryStorage()
USER_STATE = UserState(MEMORY)
CONVERSATION_STATE = ConversationState(MEMORY)

# Create dialog
DIALOG = MainDialog(CONFIG.CONNECTION_NAME)

# Create Bot
BOT = TeamsBot(CONVERSATION_STATE, USER_STATE, DIALOG)


# 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=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)

    activity = Activity().deserialize(body)
    auth_header = req.headers[
示例#23
0
        # Send a trace activity, which will be displayed in Bot Framework Emulator
        await context.send_activity(trace_activity)

    # Clear out state
    await CONVERSATION_STATE.delete(context)


ADAPTER.on_turn_error = MethodType(on_error, ADAPTER)

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

# Create dialog and Bot
DIALOG = MainDialog()
BOT = RichCardsBot(CONVERSATION_STATE, USER_STATE, DIALOG)


# Listen for incoming requests on /api/messages.
@APP.route("/api/messages", methods=["POST"])
def messages():
    # Main bot message handler.s
    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 "")
示例#24
0
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(CONFIG)
LEHOI_DIALOG = LehoiDialog()
DIADIEM_DIALOG = DiadiemDialog()
DANTOC_DIALOG = DantocDialog()
GOIYLEHOI_DIALOG = GoiyLehoiDialog()
GOIYLEHOI2_DIALOG = GoiyLehoiDialog2()

DIALOG = MainDialog(RECOGNIZER, LEHOI_DIALOG, DIADIEM_DIALOG, DANTOC_DIALOG,
                    GOIYLEHOI_DIALOG, GOIYLEHOI2_DIALOG)

BOT = DialogAndWelcomeBot(CONVERSATION_STATE, USER_STATE, DIALOG)


# Listen for incoming requests on /api/messages.
async def messages(req: Request) -> Response:
    # Main bot message handler.
    # print(req)
    if "application/json" in req.headers["Content-Type"]:
        body = await req.json()
        if 'text' in body:
            body['text'] = body['text'].lower()
    else:
        return Response(status=415)
示例#25
0
文件: app.py 项目: IdanAtias/Felix
            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 MemoryStorage and state
MEMORY = MemoryStorage()
USER_STATE = UserState(MEMORY)
CONVERSATION_STATE = ConversationState(MEMORY)

# Create dialog
DIALOG = MainDialog(azure_connection_name=CONFIG.AAD_CONNECTION_NAME,
                    gcp_connection_name=CONFIG.GCP_CONNECTION_NAME)

# Create Bot
BOT = Felix(CONVERSATION_STATE, USER_STATE, DIALOG)


# 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=HTTPStatus.UNSUPPORTED_MEDIA_TYPE)

    activity = Activity().deserialize(body)
    auth_header = req.headers[
示例#26
0
        # 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 MemoryStorage and state
MEMORY = MemoryStorage()
USER_STATE = UserState(MEMORY)
CONVERSATION_STATE = ConversationState(MEMORY)

# Create the logged users dict
LOGGED_USERS: Dict[str, str] = dict()

# Create dialog
MAIN_DIALOG = MainDialog(CONFIG.CONNECTION_NAME, USER_STATE, LOGGED_USERS)

# Create a conversation references
CONVERSATION_REFERENCES: Dict[str, ConversationReference] = dict()

# Create Bot
BOT = WellcomeHomeBot(conversation_state=CONVERSATION_STATE,
                      user_state=USER_STATE,
                      dialog=MAIN_DIALOG,
                      coversation_references=CONVERSATION_REFERENCES)


# 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"]:
示例#27
0
        # 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

DIALOG = MainDialog(CONFIG)


# Listen for incoming requests on /api/messages
async def messages(req: Request) -> Response:
    # Create the Bot
    bot = AuthBot(CONVERSATION_STATE, USER_STATE, DIALOG)

    # 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[
示例#28
0
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:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = (
        request.headers["Authorization"] if "Authorization" in request.headers else ""
示例#29
0
#     masterkey=CONFIG.COSMOS_DB_KEY,
#     database=CONFIG.COSMOS_DB_DATABASE_ID,
#     container=CONFIG.COSMOS_DB_CONTAINER_ID
# )
# MEMORY = CosmosDbStorage(COSMOS_DB_CONFIG)
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.
ERROR_ADAPTER = ErrorAdapter(SETTINGS, CONVERSATION_STATE)

# Create dialogs and Bot
RECOGNIZER = DeliverySchedulingRecognizer(CONFIG)
DIALOG = MainDialog(RECOGNIZER, USER_STATE, MEMORY)
BOT = DeliveryBot(CONVERSATION_STATE, DIALOG, USER_STATE)

AUTHORIZATION_HEADER = "Authorization"
CONTENT_TYPE_HEADER = "Content-Type"
JSON_CONTENT_TYPE = "application/json"


# Listen for incoming requests on /api/messages
async def messages(req: Request) -> Response:
    # Main bot message handler.
    if JSON_CONTENT_TYPE in req.headers[CONTENT_TYPE_HEADER]:
        body = await req.json()
    else:
        return Response(status=415)