Skip to content

Instantly share code, notes, and snippets.

@ankitadhandha
Created July 20, 2018 14:26
Show Gist options
  • Save ankitadhandha/8ddac4a284231ac8c8bce1b822cf7069 to your computer and use it in GitHub Desktop.
Save ankitadhandha/8ddac4a284231ac8c8bce1b822cf7069 to your computer and use it in GitHub Desktop.
"use strict";
var express = require('express');
var router = express.Router();
var Slack = require('slack-node');
var multer = require('multer');
var multipart = multer();
//sending messages to slack channel
router.post('/messages', multipart.fields([]), function(req, res) {
var webhookUri = "https://hooks.slack.com/services/T0000000/B00000000/I00000000000000000000";
var slack = new Slack();
slack.setWebhook(webhookUri);
slack.webhook({
channel: "#contactus",
username: "Ankita",
text: "Contact Us message from Ontomatica:\nName: " + req.body.InputName + "\nEmail: "+ req.body.InputEmail +"\nInputPhone: "+ req.body.InputPhone + "\nMessage: "+ req.body.InputMessage +"\n"
}, function(err, response) {
});
console.log(req.body.InputMessage + 'was sent to contactus channel' + 'url: ' + req.get('host'));
res.setHeader('AMP-Access-Control-Allow-Source-Origin', 'https://'+req.get('host'));
res.json({success:true});
});
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment