Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWS Lambda function to Slack Channel hookup
var services = '/services/...'; // Update this with your Slack webhook URL path
var channel = '#fleet-status'; // Update this with the Slack channel to post in
var username = 'Vehicle GeoFence Alert'; //Update this with the Slack username to show on the posts
var https = require('https');
var util = require('util');
function vehicleName(vehicleId) {
switch (vehicleId) {
case 9999991:return "Rex";
case 9999992:return "Toro";
case 9999993:return "Ruby";
case 9999994:return "Wally";
case 9999995:return "Deuxy";
case 9999996:return "Bravo";
case 9999997:return "Duke";
case 9999998:return "eHawk";
default:"Mystery Mobile"
}
};
exports.handler = function(event, context) {
console.log(JSON.stringify(event, null, 2));
var vehicleId = event.vehicle_id;
var message = vehicleName(vehicleId) + ' is arriving at a stop! See it on the fleet dashboard: https://fleet.tesloop.com/dashboard/vehicles/' + vehicleId;
var postData = {
"channel": channel,
"username": username,
"text": message,
"icon_emoji": ":round_pushpin:"
};
var options = {
method: 'POST',
hostname: 'hooks.slack.com',
port: 443,
path: 'services'
};
var req = https.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
context.done(null);
});
});
req.on('error', function(err) {
console.log('Houston, we have a problem: ' + err.message);
});
req.write(util.format("%j", postData));
req.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.