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 either Message or CallbackQuery and absent otherwise.

In the Message case, it is the expansion of the chat part of the payload.

In the CallbackQuery case, it can be:

  • the expansion of the chat part inside the message part of the Update data, if message is present (Telegram documentation states this field is optional in the API), otherwise

  • a simple anonymous hash where the id field is filled with the chat_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, then data_type will be Message. See https://core.telegram.org/bots/api#update for the mapping between type and data_type.

payload

the actual optional object pointed to by type. For example, if type is message, then payload 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 the payload

source

points to a hash containing the technology (set to telegram) and token (either inherited, or set to whatever value is pointed by key object_token in source 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

Bot::ChatBots.

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.