Пример #1
0
def test_get_message_data():
    assert story_context.get_message_data(
        {
            'session': {
                'data': {
                    'message': {
                        'text': {
                            'raw': 'I\'m going to Mars',
                        },
                        'location': {
                            'lat': 12,
                            'lng': 21,
                        }
                    }
                }
            }
        }, 'text') == {
            'raw': 'I\'m going to Mars',
        }
Пример #2
0
async def test_integrate_mongodb_with_facebook(open_db, build_context):
    async with open_db() as mongodb:
        facebook, _, story, user = await build_context(mongodb)

        trigger = utils.SimpleTrigger()

        @story.on('hello, world!')
        def correct_story():
            @story.part()
            def store_result(ctx):
                trigger.receive(ctx)

        await facebook.handle(
            build_message(user['facebook_user_id'], {'text': 'hello, world!'}))

        assert trigger.value['user'] == user
        assert story_context.get_message_data(trigger.value) == {
            'text': {
                'raw': 'hello, world!'
            }
        }
Пример #3
0
 def store_location(ctx):
     trigger_location.receive(
         story_context.get_message_data(ctx))
Пример #4
0
 def store_result(ctx):
     incorrect_trigger.receive(story_context.get_message_data(ctx))
Пример #5
0
def get_option(ctx):
    return story_context.get_message_data(ctx, 'option', 'value')
Пример #6
0
def get_raw_text(ctx, default=None):
    return story_context.get_message_data(ctx, 'text', 'raw', default=default)
Пример #7
0
def get_sticker(ctx):
    return story_context.get_message_data(ctx, 'sticker_id')
Пример #8
0
 def store_option(ctx):
     trigger.receive(
         story_context.get_message_data(ctx, 'option',
                                        'matches')[0])