pagesasfen.blogg.se

Slack webhook
Slack webhook













my $webhook = Slack::WebHook->new( url => '. Using any of the post_* methods: post_ok, post_warning, post_error, post_info, post_start or post_end you can set an alternate color to use for your Slack notification. $hook->post_end( title => "Task 42 is now finished", color => "#000", text => 'task is now finished' ) $hook->post_start( title => "Starting Task 42", text => "description." ) # using start / end with title and custom color my $hook = Slack::WebHook->new( url => ' ) This would convert the time elapsed between the two calls to a string appended at the end of your message. The post_end method should be used after calling post_start. The default color used to display the message is blue. Similar to post_ok but in addition initialize a timer which is used by post_stop. Similar to post_ok but the color used to display the message is red. Similar to post_ok but the color used to display the message is blue. Similar to post_ok but the color used to display the message is yellow. One Hash Ref containing the success field which is true on success. The return value of the method post_* is one HTTP::Tiny reply. Text => "your notification message using _markdown_", Or you can also set an optional title or change the default color used for the notification Slack::WebHook->new( URL =>. You have two ways of calling a post_* method.Įither you can simply pass a single string argument to the function Slack::WebHook->new( URL =>. Post_ok submit a POST request to the Http URL set when constructing a Slack::WebHook object. Navigate to Administration > Manage apps. The post method allow you to post custom messages by bypassing any preset layour. Enable Incoming Webhooks In your main Slack screen, click on your company name at the top of the left-hand menu. You should prefer using any of the other methods post_* which will use colors and a preset style to display your notification.

#Slack webhook code#

The success field will be true if the status code is 2xx. The return value is the return of HTTP::Tiny::post_form which is one Hash Ref. The post method allow you to post a single message without any preset decorations. You should visit the official Slack documentation page to create your webhook and get your personal URL. You should provide the url for your webhook. This is the constructor for Slack::WebHook. , auto_detect_utf8 => 0 ) Available functions / methods new( ) This is on by default but you can disable it by using my $hook = Slack::WebHook->new(. You can provide a boolean to automatically try to detect utf8 strings and enable the utf8 flag. By default utf8 = 0, pretty = 1.Įxample: my $json = Cpanel::JSON::XS->new->utf8(0)->pretty->allow_nonref One JSON::MaybeXS with the flavor of your choice. This is optional and allow you to provide an alternate JSON object to format the output sent to post queries. Set of helpers to send slack notification with preset decorations.

slack webhook

# which will be converted to JSON before posting the message

slack webhook

# this allow you to bypass the custom layout and provide your own hash struct # you can also post your own custom message without any preset styles $hook->post_end( text => 'task is now finished in black', color => '#000' ) # "\nrun time: 1 hour 12 minutes 45 seconds" # automatically adds the run time at the end of your message:

slack webhook

$hook->post_end( 'task is now finished' ) $hook->post_start( 'starting some task' ) $hook->post_info( # or any other post_* method # you can also set your own color if you want $hook->post_ok( # or any other post_* method # you can also set a title and a body to your message $hook->post_ok( text => 'a pretty _green_ message' ) $hook->post_info( 'a pretty _blue_ message' ) $hook->post_error( 'a pretty _red_ message' ) $hook->post_warning( 'a pretty _orange_ message' ) $hook->post_ok( 'a pretty _green_ message' ) # using some preset decorations with markdown syntax enabled Sample usage to post slack notifications using Slack::WebHook #!perl Slack::WebHook - Slack WebHook with preset layout & colors for sending slack notifications VERSION Assume that you use the following CURL command to post to Slack.













Slack webhook