NAME

Telegram::BotKit::Screens - Implements navigation by screens JSON file. Used by Telegram::BotKit::Wizard

VERSION

version 0.02

SYNOPSIS

	# $screens_arrayref:

	"screens" : [
	    { "name": "item_select", "start_command": "/book", "welcome_msg": "Please select an item to book", "keyboard":
	      [
	        { "key": "Item 1", "answ" : "Good" },
	        { "key": "Item 2", "answ" : "Well" },
	        { "key": "Item 3", "answ" : "Fine" }
	      ] 
	    }, 
	    { "name": "day_select", "parent": "item_select", "welcome_msg": "Please select a day", "keyboard":
	      [
	        { "key": "today" }, 
	        { "key": "tomorrow" }
	      ]
    	},
	    { "name": "today_time_picker", 
	      "parent": "day_select", 
	      "callback_msg": "today", 
	      "kb_build_func": "dynamic1_build_func"
	    },
	    { "name": "tomorrow_time_picker", 
	      "parent": "day_select", 
	      "callback_msg": "tomorrow", 
	      "kb_build_func": "dynamic2_build_func"
	    }
    ]

	use Telegram::Screens;
	my $screens->Telegram::Screens->new($screens_arrayref);
	
	$screens->get_screen_by_name("item_select")->{name}; # day_select
	
	$screens->get_next_screen_by_name("item_select")->{name}; # day_select
	$screens->get_next_screen_by_name("day_select", "today")->{name}; # today_time_picker
	
	$screens->get_prev_screen_by_name("day_select")->{name}; # item_select
	
	$screens->level("item_select");  # 0
	$screens->level("day_select");  # 1
	$screens->level("today_time_picker");  # 2
	$screens->level("tomorrow_time_picker");  # 2

	$screens->get_screen_by_start_cmd("/book")->{name}; # item_select

	$screen->is_last_screen('item_select'); # 0
	$screen->is_last_screen('tomorrow_time_picker'); # 1

	$screens->get_keys_arrayref('item_select'); # ["Item 1", "Item 2", "Item 3"]
	
	$screens->get_keys_arrayref('item_select'); # ["Good", "Well", "Fine"]

	$screens->get_answ_by_key('item_select', 'Item 1');  # Good

METHODS

get_screen_by_name

Return screen item by its name

Screen name must be unique accross json file

$screens->get_screen_by_name("item_select")->{name}; # item_select

get_next_screen_by_name

Return next screen item by current screen name and text reply on current screen

Resolve screen relationships by parent and callback_msg fields

	"screens" : [
	    { "name": "item_select", "start_command": "/book", "welcome_msg": "Please select an item to book", "keyboard":
	      [
	        { "key": "Item 1", "answ" : "Good" },
	        { "key": "Item 2", "answ" : "Well" },
	        { "key": "Item 3", "answ" : "Fine" }
	      ] 
	    }, 
		{ "name": "day_select", "parent": "item_select", "welcome_msg": "Please select a day", "keyboard":
	      [
	        { "key": "today" }, 
	        { "key": "tomorrow" }
	      ]
    	},
	    { "name": "today_time_picker", 
	      "parent": "day_select", 
	      "callback_msg": "today", 
	      "kb_build_func": "dynamic1_build_func"
	    },
	    { "name": "tomorrow_time_picker", 
	      "parent": "day_select", 
	      "callback_msg": "tomorrow", 
	      "kb_build_func": "dynamic2_build_func"
	    }
	]

$screens->get_next_screen_by_name("item_select")->{name}; # day_select $screens->get_next_screen_by_name("day_select", "today")->{name}; # today_time_picker $screens->get_next_screen_by_name("day_select", "todmorrow")->{name}; # tomorrow_time_picker

get_prev_screen_by_name

Return previous screen

$screens->get_prev_screen_by_name("day_select")->{name}; # item_select

level

Return screen level according call sequence. First screen has level 0.

$screens->level("item_select"); # 0 $screens->level("day_select"); # 1

get_screen_by_start_cmd

Return screen item if it contains start_command

"screens" : [
    { "name": "item_select", "start_command": "/book", "welcome_msg": "Please select an item to book", "keyboard":
      [
        { "key": "Item 1", "answ" : "Good" },
        { "key": "Item 2", "answ" : "Well" },
        { "key": "Item 3", "answ" : "Fine" }
      ] 
    }, ...
 ]

$screens->get_screen_by_start_cmd("/book")->{name}; # item_select

is_last_screen

Return true if screen is last screen

$screen->is_last_screen('item_select'); # 0 $screen->is_last_screen('tomorrow_time_picker'); # 1

is_first_screen

Return true if screen is first screen

$screen->is_last_screen('item_select'); # 1 $screen->is_last_screen('tomorrow_time_picker'); # 0

is_static

Return true if screen item has keyboard value (sign of static screen)

get_keys_arrayref

Return all "key" fields of "keyboard" property as array

"screens" : [ { "name": "item_select", "start_command": "/book", "welcome_msg": "Please select an item to book", "keyboard": [ { "key": "Item 1", "answ" : "Good" }, { "key": "Item 2", "answ" : "Well" }, { "key": "Item 3", "answ" : "Fine" } ] }, ...

$screens->get_keys_arrayref('item_select'); # ["Item 1", "Item 2", "Item 3"]

get_answers_arrayref

Return all "answ" fields of "keyboard" property as array

"screens" : [ { "name": "item_select", "start_command": "/book", "welcome_msg": "Please select an item to book", "keyboard": [ { "key": "Item 1", "answ" : "Good" }, { "key": "Item 2", "answ" : "Well" }, { "key": "Item 3", "answ" : "Fine" } ] }, ...

$screens->get_answers_arrayref('item_select'); # ["Good", "Well", "Fine"]

get_answ_by_key

Return reply to particular button

"screens" : [ { "name": "item_select", "start_command": "/book", "welcome_msg": "Please select an item to book", "keyboard": [ { "key": "Item 1", "answ" : "Good" }, { "key": "Item 2", "answ" : "Well" }, { "key": "Item 3", "answ" : "Fine" } ] }, ...

$screens->get_answ_by_key('item_select', 'Item 1'); # Good

AUTHOR

Pavel Serikov <pavelsr@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Pavel Serikov.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.