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', }
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!' } }
def store_location(ctx): trigger_location.receive( story_context.get_message_data(ctx))
def store_result(ctx): incorrect_trigger.receive(story_context.get_message_data(ctx))
def get_option(ctx): return story_context.get_message_data(ctx, 'option', 'value')
def get_raw_text(ctx, default=None): return story_context.get_message_data(ctx, 'text', 'raw', default=default)
def get_sticker(ctx): return story_context.get_message_data(ctx, 'sticker_id')
def store_option(ctx): trigger.receive( story_context.get_message_data(ctx, 'option', 'matches')[0])