Create a notification channel to send health status requests using your company's
preferred communication method, such as the Slack or Microsoft Teams collaboration platforms. Create the notification channel
using a script or a subflow.
After you create a notification channel, you can select
the channel when sending a notification. The channel uses the specified subject and
body, and sends notifications to the users that you select when you send the health
status request.For example, your company's IT network group has a Slack channel that they monitor more closely than email. Create a Slack
notification channel. To communicate with IT network group members, select the group
as the target audience and select the Slack notification
channel.
If the Email notification and Now
Mobile Push notification check boxes are selected, all three
notifications are sent. To use only the Slack notification channel,
clear these two check boxes.
Example: Slack channel script
Note: The following script is for reference only. Refer to it when you develop a
notification channel script for your environment.
(function notify(responses, channelGr) {
var createClient = function () {
var client = new sn_ws.RESTMessageV2();
client.setRequestHeader('Authorization', 'Bearer xoxb-222222222222-1111111111111-000000000000000000000000');
client.setRequestHeader("Accept", "application/json");
client.setRequestHeader('Content-type', 'application/json');
return client;
};
var getEmailToSlackIdMap = function (users) {
var emailToSlackIdMap = {};
for (var i = 0; i < users.length; i++) {
var email = users[i].profile.email;
if (email) {
emailToSlackIdMap[email] = users[i].id;
}
}
return emailToSlackIdMap;
};
var runSlackCommand = function (method, params) {
var client = createClient();
client.setHttpMethod('post');
client.setEndpoint('https://slack.com/api/' + method);
client.setRequestBody(JSON.stringify(params));
var response = client.execute();
if (response.getStatusCode() < 200 || response.getStatusCode() > 299) {
throw new Error('Failure running ' + method + ':\n' + response.getBody());
}
var body = JSON.parse(response.getBody());
if (!body.ok) {
throw new Error(body.error);
}
return body;
};
var sendMessage = function (userId, message) {
var openConversationResponse = runSlackCommand('conversations.open', { users: userId });
var channel = openConversationResponse.channel.id;
runSlackCommand('chat.postMessage', { channel: channel, text: message });
};
var users = runSlackCommand('users.list').members;
var emailToSlackIdMap = getEmailToSlackIdMap(users);
var body = channelGr.getValue('body') || '<p></p>';
var record = responses.mode === 'acknowledgements' ? responses.acknowledgementsGr : responses.surveyInstancesGr;
var numSent = 0;
while (record.next()) {
var email = record.user.email + '';
var link = responses.mode === 'acknowledgements'
? gs.getProperty('glide.servlet.uri') + record.getLink(true)
: gs.getProperty('glide.servlet.uri') + 'sp?id=take_survey&instance_id=' + record.getUniqueValue();
var message = body + '\n' + link;
var slackId = emailToSlackIdMap[email];
if (slackId) {
sendMessage(slackId, message);
numSent += 1;
}
}
return { sent_count: numSent };
})(responses, channelGr);