An open API service indexing awesome lists of open source software.

https://github.com/nitor-infotech-oss/go-slacknotification

Send notifications on slack channel in golang using slack webhook url
https://github.com/nitor-infotech-oss/go-slacknotification

Last synced: 7 months ago
JSON representation

Send notifications on slack channel in golang using slack webhook url

Awesome Lists containing this project

README

          

# slacknotifications

[![Build Status](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://travis-ci.org/joemccann/dillinger)

# Objective

Slack allows you to create webhooks which can be used as an API endpoints and sent messages programmatically.
A many time, we do want our process to send us the slack notifications.

### Prerequisites
There are no dependencies on any of the GoLang packages.

### Imprting Package

```
import (
"github.com/nitor-infotech-oss/go-slacknotification/slacknotifications"
)
```

Package can be imported by simply using the path of repo where it resides.

### Example Usage

```
package main
import (
"fmt"
"github.com/nitor-infotech-oss/go-slacknotification/slacknotifications"
)

func main() {
webhookUrl := "https://hooks.slack.com/services/XXXXXXX/XXXXXXXXXXXXXXX/XXXXXXXXXXXXXXX"
err = slacknotifications.SendSlackNotification(webhookUrl, summaryString)
if err != nil {
fmt.Println("Error while sending msg to slack")
}
}
```

### Steps to generate webhook url from slack

- To get the correct webhook url on which we have post the messages, need to add configuration on the incoming WebHoks page.

- Go to https://my.slack.com/services/new/incoming-webhook/ link, it may ask you to log in
![alt text](https://i.ibb.co/g7m9vmY/webhook1.png)
- Choose the channel you want to post the messages and click on the Add Incoming Webhooks integration button.
- Once you click above mentioned button this will give you the webhook url (e.g. https://hooks.slack.com/services/XXXXX/xxxxxxx/xxxxxxxxxxxxxx)
![alt text](https://i.ibb.co/M1TYCNW/webhook2.png)