Wondering how to trigger alerts from Slack messages?
It is not just a messaging app; it is so much more with its apps. Opsgenie’s integration with Slack is so thorough that it has become a top app in the Slack app directory!
Opsgenie's Slack app has built-in slash commands, which is an efficient way to execute actions on a channel. For example, you have the option to create an Opsgenie alert in a channel by typing a command like /genie alert [alert message] for [user team]. Slash commands are very powerful and cover the majority of the use-cases. However, there may be more you want to do in your Slack channel.
Our customers began with asking how they can create alerts from messages sent to a Slack channel. Opsgenie is flexible. What you can do with our API and client SDK’s are close to limitless! Slack also provides great solutions for such use-cases.
We created a sample application to show how you can do this easily. For these kinds of custom solutions, we prefer to use AWS Lambda to eliminate operational costs. In this solution, we also needed an https endpoint, so we used AWS API Gateway service as well.
Outgoing webhooks are used to get data out of Slack in real time. Basically, Slack sends the messages to our API Gateway endpoint, and we create an alert in Opsgenie by using ourNode.js SDK to keep the code simple.
Before sharing the code and setup details, we should point out that this is a very simple integration and it creates an alert in Opsgenie for each message sent to the specified channel. However, let’s say you need more than that and you want to create alerts for the Slack messages that contain “alert” text.
To create alerts from Slack messages you have two options:
Define a trigger_word in the Outgoing webhook. In this case, Slack will only post the messages that contain “alert” text.
Update the code we share with you. You can filter the messages based on its content, add additional data to your messages, or get additional information from an external service to enrich your alerts.
Although this script is straightforward and short, it represents a powerful concept. You can create custom solutions by using our APIs and client SDKs along with AWS services without having to worry about implementation details, how to manage your servers, or how to deploy your applications. We have also usedserverless.js to provision our application. Creating and updating your Lambda function or creating your API Getaway trigger could be tricky. Yet, Serverless.js makes it simpler and easier.
To setup and use this integration, you can visitour GitHub repository and follow the steps described in the README file. For creating a full-featured Slack app with incoming webhooks or events APIs, you might want to take a look at John Agan’s repository. It truly does a lot for you!
If you have any questions about the implementation, you are welcome to contact us!
Just don’t forget to play with the code to make it more powerful!