AnyEvent-SlackBot

 view release on metacpan or  search on metacpan

lib/AnyEvent/SlackBot.pm  view on Meta::CPAN

271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
  my $id=$self->next_id;
  my $msg={
    bot_id=>$self->bot_id,
    channel=>$json->{channel},
    id=>$id,
    type=>'typing',
  };
  $self->send($msg);
}
 
=item * $self->post_to_web($msg,$endpoint|undef,"FORM"|"JSON"|undef)
 
Posts the to the given REST Endpoint outside of the WebSocket.
 
  msg:
    Hash ref representing the requrest being sent
      token: set to $self->token if not set
      scope: set to: 'chat:write:bot' if not set
 
  endpoint:
    The Rest xxx endpint, the default is 'chat.postMessage'
 
  type:
    Sets how the data will be sent over
    Supported options are:
      - FORM: posts the data using form encoding
      - JSON: converts $msg to a json string and posts
 
=cut
 
sub post_to_web {
  my ($self,$msg,$endpoint,$type)=@_;
  $endpoint='chat.postMessage' unless defined($endpoint);
  $type='FORM';
 
  $self->stats->{running_posts}++;
  my $url="https://slack.com/api/$endpoint";
 
 
  $msg->{token}=$self->token unless exists $msg->{token};
  $msg->{scope}='chat:write:bot'  unless exists $msg->{scope};
 
  my $request;
 
  if($type eq 'FORM') {
    $request=POST $url,[%{$msg}];
  } else {



( run in 0.891 second using v1.01-cache-2.11-cpan-49f99fa48dc )