2015-03-08 57 views

回答

0

是的,这里是perl中的一个例子,它使用hostname和pid来生成bot的名字。

sub slack { 
    my ($message) = @_; 

    use LWP::UserAgent; 
    use HTTP::Request; 
    use Sys::Hostname; 

    my $uri = "https://hooks.slack.com/services/" 
    . "this-is-your-api-key"; 

    my $json = '{"channel": "#example_channel", ' 
    . '"username": "' . hostname . "." . $$ . '", ' 
    . '"text": "' . $message . '", ' 
    . '"icon_emoji": ":trollface:"}' ; 

    my $request = HTTP::Request->new('POST', $uri); 
    $request->header('Content-Type' => 'application/json'); 
    $request->content($json); 

    my $agent = LWP::UserAgent->new; 

    my $result = $agent->request($request); 
} 
0

当发送通过进入网络挂接一个消息,你必须发送一个参数username指定的名称,将出现即

{ 
    "text": "the message i'm sending", 
    "name": "whatever-name-you-want" 
} 

的选项(您也可以在每封邮件指定一个不同的图标使用icon_url参数以及所需图像的URL值)

相关问题