Create an Emergency Outreach notification channel
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.
Vorbereitungen
Role required: sn_imt_checkin.checkin_admin or admin
Warum und wann dieser Vorgang ausgeführt wird
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.
Prozedur
When an outreach is sent using a custom notification channel, a Delivery Logs related list appears in the Outreach message.
- Test the notification channel for an outreach message, and open the failed record to review the error message.
- Fix errors that caused the notification to fail.
- Continue testing the notification channel until it no longer fails.
Slack channel script
(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);