Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Client used to build and send Slack messages to a channel, using a slack incoming webhook which can easily configured

License

NotificationsYou must be signed in to change notification settings

micdah/SlackWebhook

Repository files navigation

Build statusNuGet

Provides a simple .Net client for using Slack'sIncoming Webhooks URL's tosend messages to a slack channel of your choosing.

The Webhooks API is pretty simple, but it always preferable to have a typed interface to use rather than an untyped(and undocumented) JSON object. So using this library should make it simpler to build a slack message and send itusing a webhook URL.

Seechangelog for version history.

Example

Foo

How to use

Firstinstall the nuget package:

PM> Install-Package SlackWebhook

Next simply use theSlackClient class to send a message:

awaitnewSlackClient(webhookUrl).SendAsync(b=>b.WithUsername("Slack Bot Name").WithIcon(IconType.Url,"http://my.host/bot_icon.png").WithText("Something very interesting just happened"));

How to obtain Incoming Webhook URL

In the above example i used thewebhookUrl which you obtain by adding theIncoming WebHooks app configurationto the channel you want to send messages to (each url is tied to a specific channel, so if you want to sent todifferent channels, just add multiple configurations).

  1. Openslack.com/services/new/incoming-webhook
  2. UnderPost to Channel select the channel you want to send to
  3. PressAdd Incoming WebHooks integration
  4. Now copy theWebhook URL

What is supported?

Besides the message, the Slack hook also allows attachments which are pretty neat.In the above example I used a few attachments and fields to illustrate some of the uses. Especially the attachmentfields are a good way to include extra detail in a table-like structure (by settingshort flag on field, two fieldswill be shown in the attachment side-by-side for each row).

My example was generated by this code:

awaitnewSlackClient(webhookUrl).SendAsync(b=>b.WithText("Hello from *SlackWebhook*").WithUsername("SlackWebhook").WithIcon(IconType.Url,"https://raw.githubusercontent.com/micdah/SlackWebhook/master/icon.png").WithAttachment(a=>a.WithTitle("How to install").WithText("`PM> Install-Package SlackWebhook`").WithColor(Color.DarkSlateBlue)).WithAttachment(a=>a.WithTitle("Find out more").WithText("Find out more by taking a look at github.com/micdah/SlackWebhook").WithLink("https://github.com/micdah/SlackWebhook").WithField("Use builder pattern","```\n"+"await slackClient.SendASync(b => b\n"+"   .WithUsername(\"My Bot\")\n"+"   .WithText(\"Hello *World*\"));\n"+"```").WithField("Use object initializer","```\n"+"await slackClient.SendAsync(new SlackMessage {\n"+"   Username =\"My Bot\",\n"+"   Text =\"Hello *World*\"\n"+"});\n"+"```")));

Documentation

You can find the documentation inSlackWebhook, of particularinterest are these:

About

Client used to build and send Slack messages to a channel, using a slack incoming webhook which can easily configured

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp