Exemplo n.º 1
0
def dm():
    dialogue_manager = DialogueManager(async_mode=True)
    dialogue_manager.called_async_handler = False

    @dialogue_manager.handle(domain="domain")
    async def domain(ctx, handler):
        pass

    @dialogue_manager.handle(intent="intent")
    async def intent(ctx, handler):
        pass

    @dialogue_manager.handle(domain="domain", intent="intent")
    async def domain_intent(ctx, handler):
        pass

    @dialogue_manager.handle(intent="intent", has_entity="entity_1")
    async def intent_entity_1(ctx, handler):
        pass

    @dialogue_manager.handle(intent="intent", has_entity="entity_2")
    async def intent_entity_2(ctx, handler):
        pass

    @dialogue_manager.handle(
        intent="intent", has_entities=("entity_1", "entity_2", "entity_3")
    )
    async def intent_entities(ctx, handler):
        pass

    @dialogue_manager.handle(targeted_only=True)
    async def targeted_only(ctx, handler):
        pass

    # Defined to test default use
    @dialogue_manager.handle()
    async def dummy_ruleless(ctx, handler):
        pass

    @dialogue_manager.handle(default=True)
    async def default(ctx, handler):
        pass

    @dialogue_manager.handle(intent="async")
    async def async_handler(_, responder):
        await asyncio.sleep(0.050)
        dialogue_manager.called_async_handler = True
        responder.reply("this is the async handler")

    return dialogue_manager
Exemplo n.º 2
0
def dm():
    dialogue_manager = DialogueManager(async_mode=True)
    dialogue_manager.called_async_handler = False

    @dialogue_manager.handle(domain='domain')
    async def domain(ctx, handler):
        pass

    @dialogue_manager.handle(intent='intent')
    async def intent(ctx, handler):
        pass

    @dialogue_manager.handle(domain='domain', intent='intent')
    async def domain_intent(ctx, handler):
        pass

    @dialogue_manager.handle(intent='intent', has_entity='entity_1')
    async def intent_entity_1(ctx, handler):
        pass

    @dialogue_manager.handle(intent='intent', has_entity='entity_2')
    async def intent_entity_2(ctx, handler):
        pass

    @dialogue_manager.handle(intent='intent',
                             has_entities=('entity_1', 'entity_2', 'entity_3'))
    async def intent_entities(ctx, handler):
        pass

    @dialogue_manager.handle(targeted_only=True)
    async def targeted_only(ctx, handler):
        pass

    # Defined to test default use
    @dialogue_manager.handle()
    async def dummy_ruleless(ctx, handler):
        pass

    @dialogue_manager.handle(default=True)
    async def default(ctx, handler):
        pass

    @dialogue_manager.handle(intent='async')
    async def async_handler(_, responder):
        await asyncio.sleep(0.050)
        dialogue_manager.called_async_handler = True
        responder.reply('this is the async handler')

    return dialogue_manager