LINE-Bot-API
view release on metacpan or search on metacpan
lib/LINE/Bot/Message/Narrowcast.pm view on Meta::CPAN
package LINE::Bot::Message::Narrowcast;
use strict;
use warnings;
use LINE::Bot::API::Client;
use LINE::Bot::API::Response::NarrowcastStatus;
use constant {
DEFAULT_MESSAGING_API_ENDPOINT => 'https://api.line.me/v2/bot/',
};
sub new {
my ($class, %args) = @_;
my $client = LINE::Bot::API::Client->new(%args);
bless {
client => $client,
channel_secret => $args{channel_secret},
channel_access_token => $args{channel_access_token},
messaging_api_endpoint => $args{messaging_api_endpoint} // DEFAULT_MESSAGING_API_ENDPOINT,
}, $class;
}
sub request {
my ($self, $method, $path, @payload) = @_;
return $self->{client}->$method(
$self->{messaging_api_endpoint} . $path,
@payload,
);
}
sub send_message {
my ($self, $messages, $recipient, $demographic, $limit, $options) = @_;
my @headers = ();
if ($options && defined($options->{'retry_key'})) {
push @headers, 'X-Line-Retry-Key' => $options->{'retry_key'};
}
my $res = $self->request(
post => 'message/narrowcast',
\@headers,
+{
messages => $messages,
recipient => $recipient,
filter => {
demographic => $demographic,
},
limit => $limit,
},
);
LINE::Bot::API::Response::Common->new(%{ $res });
}
sub get_narrowcast_message_status {
my ($self, $request_id) = @_;
my $res = $self->request(
get => "message/progress/narrowcast?requestId=${request_id}"
);
LINE::Bot::API::Response::NarrowcastStatus->new(%{ $res });
}
1;
__END__
=head1 NAME
LINE::Bot::Message::Narrowcast
=head2 Methods
=head3 C<< send_message($messages, $recipient, $demographic, $limit, $options) >>
Sends a push message to multiple users.
C<$message> is a HashRef with key/values for as specified in API reference of this method: L<https://developers.line.biz/en/reference/messaging-api/#send-narrowcast-message>. nested keys are represented in the dotted notations.
C<$recipient> should be an HashRef with keys/values as specified in the documentation of L<Recipient objects|https://developers.line.biz/en/reference/messaging-api/#narrowcast-recipient>. It can be either audience object or redelivery object. You can...
C<$demographic> should be an HashRef with key/values as specified in the documentation of L<Demagraphic filter object|https://developers.line.biz/en/reference/messaging-api/#narrowcast-demographic-filter>. It represent criteria (e.g. age, gender, OS,...
C<$limit> should be an HashRef with these optional key-value pairs:
max: Number
( run in 0.745 second using v1.01-cache-2.11-cpan-524268b4103 )