NAME
Bot::ChatBots::Telegram::Role::Source - Telegram Source Role
SYNOPSIS
package Some::Thing;
use Moo;
with 'Bot::ChatBots::Telegram::Role::Source';
...
DESCRIPTION
This role is meant to be consumed by Bot::ChatBots::Telegram::WebHook and Bot::ChatBots::Telegram::LongPoll.
ACCESSORS
This role defines the accessors in the following subsections.
sender
my $sender = $obj->sender;
$obj->sender(Bot::ChatBots::Telegram::Sender->new(token => $token));
Accessor for the Bot::ChatBots::Telegram::Sender object useful for managing communications to Telegram.
token
my $token = $obj->token;
$obj->token($ENV{TOKEN});
Accessor for the token, used to access the Telegram service remotely. This also has an associated predicate function "has_token".
METHODS
This method defines the methods in the following subsections.
has_token
say 'yes!' if $obj->has_token;
Predicate function to assess whether a "token" is present or not.
normalize_record
my $record = $self->normlize_record($input_record);
Perform some normalization on the record to give it a more "general" shape. Which is still in a state of flux, so a look to the code might be helpful.
So far you should find the following keys in the returned record:
chan
-
optional element containing data about the Chat where the Update came from. It is present when
data_type
is eitherMessage
orCallbackQuery
and absent otherwise.In the
Message
case, it is the expansion of thechat
part of thepayload
.In the
CallbackQuery
case, it can be:the expansion of the
chat
part inside themessage
part of the Update data, ifmessage
is present (Telegram documentation states this field is optional in the API), otherwisea simple anonymous hash where the
id
field is filled with thechat_instance
field from the payload. Whether this is meaningful or not is debatable.
data_type
-
the Telegram type for the data pointed to by the optional field. For example, if the optional field in the Update is
edited_message
, thendata_type
will beMessage
. See https://core.telegram.org/bots/api#update for the mapping betweentype
anddata_type
. payload
-
the actual optional object pointed to by
type
. For example, iftype
ismessage
, thenpayload
will point to a hash with the contents explained at https://core.telegram.org/bots/api#message. sender
-
whatever is contained in the
from
field of thepayload
source
-
points to a hash containing the
technology
(set totelegram
) andtoken
(either inherited, or set to whatever value is pointed by keyobject_token
insource
itself) type
-
the field name of the optional part in a Telegram's Update, see https://core.telegram.org/bots/api#update (e.g.
message
,edited_message
and so on).
SEE ALSO
AUTHOR
Flavio Poletti <polettix@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2016, 2018 by Flavio Poletti <polettix@cpan.org>
This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.