async def handle(self): self.send( lyr.Text(t.HOW_ARE_YOU), fbl.QuickRepliesList([ fbl.QuickRepliesList.TextOption('yes', t.YES, intents.YES), fbl.QuickRepliesList.TextOption('no', t.NO, intents.NO), ]), )
def test_match_layer(): s = make_stack( layers.Text('yolo'), layers.Text('pouet'), fbl.QuickRepliesList([]), ) s.match_exp('(Text|RawText)+ QuickRepliesList?')
async def handle(self) -> None: self.send( lyr.Text(t.CONGRATULATIONS), fbl.QuickRepliesList([ fbl.QuickRepliesList.TextOption( slug='again', text=t.PLAY_AGAIN, intent=its.PLAY_AGAIN, ), ]), )
async def handle(self) -> None: name = await self.request.user.get_friendly_name() self.send( lyr.Text(t('WELCOME', name=name)), fbl.QuickRepliesList([ fbl.QuickRepliesList.TextOption( slug='play', text=t.LETS_PLAY, intent=its.LETS_PLAY, ), ]), )
def test_flush_qr(): args = [] kwargs = {} async def do_flush(*a, **k): args.extend(a) kwargs.update(k) mm = MiddlewareManager.instance() mm.middlewares = [AutoSleep] flush = mm.get('flush', do_flush) run( flush(None, [ lyr.Stack([ lyr.Text('hello'), lyr.Text('wassup'), fbl.QuickRepliesList([]), ]), ])) assert args == [ None, [ lyr.Stack([ lyr.RawText('hello'), ]), lyr.Stack([ lyr.Sleep(0.7), ]), lyr.Stack([ lyr.RawText('wassup'), fbl.QuickRepliesList([]), ]), ] ] assert kwargs == {}
def test_quick_replies_player_patch(text_request): l = fbl.QuickRepliesList([ fbl.QuickRepliesList.TextOption('foo', 'Foo'), fbl.QuickRepliesList.TextOption('bar', 'Bar', intents.BAR), fbl.QuickRepliesList.LocationOption(), ]) assert run(l.patch_register({}, text_request)) == { 'choices': { 'foo': { 'intent': None, 'text': 'Foo', }, 'bar': { 'intent': 'BAR', 'text': 'Bar', } } }
def test_story_hello(): with patch_conf(settings_file=ENGINE_SETTINGS_FILE): _, platform = make_test_fsm() platform.handle(l.Text('Hello!'), ) platform.assert_state(HowAreYou) platform.assert_sent( stack(l.Text(t.HELLO)), stack( l.Text(t.HOW_ARE_YOU), fbl.QuickRepliesList([ fbl.QuickRepliesList.TextOption('yes', t.YES, intents.YES), fbl.QuickRepliesList.TextOption('no', t.NO, intents.NO), ])), ) platform.handle( l.Text('Yes'), fbl.QuickReply('yes'), ) platform.assert_sent(stack(l.Text(t.GREAT)))
def test_stack(): l1 = layers.Text('hello') l2 = layers.Text('sup?') l3 = fbl.QuickRepliesList([ fbl.QuickRepliesList.TextOption('foo', 'Foo'), fbl.QuickRepliesList.TextOption('bar', 'Bar', intents.BAR), fbl.QuickRepliesList.LocationOption(), ]) stack = layers.Stack([l1]) assert stack.has_layer(layers.Text) assert not stack.has_layer(fbl.QuickRepliesList) assert stack.get_layer(layers.Text) == l1 with pytest.raises(KeyError): assert stack.get_layer(fbl.QuickRepliesList) is None stack.layers = [l1, l2, l3] assert stack.has_layer(fbl.QuickRepliesList) assert stack.get_layer(layers.Text) == l1 assert stack.get_layers(layers.Text) == [l1, l2] assert stack.get_layer(fbl.QuickRepliesList) == l3