How to use the @slack/client.IncomingWebhook function in @slack/client

To help you get started, we’ve selected a few @slack/client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bulwark-crypto / bulwark-explorer / cron / block.js View on Github external
block.vinsCount = vinsCount;
    block.voutsCount = voutsCount;

    // Notice how this is done at the end. If we crash half way through syncing a block, we'll re-try till the block was correctly saved.
    await block.save();

    const syncPercent = ((block.height / stop) * 100).toFixed(2);
    console.dateLog(`(${syncPercent}%) Height: ${block.height}/${stop} Hash: ${block.hash} Txs: ${block.txs.length} Vins: ${vinsCount} Vouts: ${voutsCount}`);

    blockSyncing = false;
  }

  // Post an update to slack incoming webhook if url is
  // provided in config.js.
  if (block && !!config.slack && !!config.slack.url) {
    const webhook = new IncomingWebhook(config.slack.url);
    const superblock = await rpc.call('getnextsuperblock');
    const finalBlock = superblock - 1920;

    let text = '';
    // If finalization period is within 12 hours (12 * 60 * 60) / 90 = 480
    if (block.height == (finalBlock - 480)) {
      text = `
      Finalization window starts in 12 hours.\n
      \n
      Current block: ${block.height}\n
      Finalization block: ${finalBlock}\n
      Budget payment block: ${superblock}\n
      https://explorer.bulwarkcrypto.com/#/block/${block.height}\n
      `;
    }
    // If finalization block.
github Konnng / maringa.com-devjob-scrapper / index.js View on Github external
fs.writeFileSync(outputFile, result)

    // INTEGRATION WITH DEVPARANA SLACK --------------------------------------------------------------------------------------------
    _log('Done generating HTML file: ', outputFile)
    _log('Cheking for new job entries to send to Slack...')

    const botJobs = db.get('jobs').filter({ bot_processed: false })
      .filter({ is_filled: false }).filter(row => row.date_processed >= cuttingTime)
      .sortBy('date').reverse().value()

    sleep(1000)

    if (botJobs.length) {
      _log(`Found ${botJobs.length} entries to be posted on slack.`)

      const slackWebhook = new IncomingWebhook(SLACK_WEBHOOK)

      const slackQueue = botJobs.slice().map((item, index) => {
        return (thread) => new Promise((resolve, reject) => {
          _log(`Processing item ${(index + 1)}:`, `${item.title} / ${item.company}`)

          const params = {
            text: `*${item.title} / ${item.company}* - ${item.url}`
          }

          if (thread) {
            params.thread_ts = thread
          }

          slackWebhook.send(params, (err, res) => {
            if (err) {
              throw err
github ngduc / node-rem / src / api / utils / MsgUtils.ts View on Github external
const fs = require('fs');

// configure for Slack
const { SLACK_WEBHOOK_URL } = require('config/vars');
const { IncomingWebhook } = require('@slack/client');
let incomingWebhook: any = null;
if (SLACK_WEBHOOK_URL) {
  incomingWebhook = new IncomingWebhook(SLACK_WEBHOOK_URL);
}

// configure for emailing
const { EMAIL_MAILGUN_API_KEY, EMAIL_FROM_SUPPORT, EMAIL_MAILGUN_DOMAIN, EMAIL_TEMPLATE_BASE } = require('config/vars');
const handlebars = require('handlebars');

// load template file & inject data => return content with injected data.
const template = (fileName: string, data: any) => {
  const content = fs.readFileSync(EMAIL_TEMPLATE_BASE + fileName).toString();
  const inject = handlebars.compile(content);
  return inject(data);
};

// --------- Email Templates --------- //

export function welcomeEmail({ name, email }: { name: string; email: string }) {
github DeviaVir / zenbot / extensions / notifiers / slack.js View on Github external
pushMessage: function(title, message) {
      var slackWebhook = new IncomingWebhook(config.webhook_url || '', {})
      slackWebhook.send(title + ': ' + message, function (err) {
        if (err) {
          console.error('\nerror: slack webhook')
          console.error(err)
        }
      })
    }
  }
github runnerty / runnerty / notificators / slack / slack.js View on Github external
return new Promise((resolve) => {
    var currentNotification = pendings.shift();

    if (currentNotification) {
      var wh = new IncomingWebhooks(currentNotification.webhookurl);
      wh.send({
        text: currentNotification.titleToSend,
        channel: currentNotification.channel,
        iconEmoji: currentNotification.bot_emoji,
        username: currentNotification.bot_name,
        attachments: [
          {
            text: currentNotification.msgToSend,
            color: currentNotification.color
          }
        ]
      }, function () {
        resolve();
      });
    } else {
      resolve();
github binaris / binaris / sdk / feedback.js View on Github external
const feedback = async function feedback(realm, funcData) {
  const slackWebhookUrl = String('https://hooks.slack.com/services/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');
  let result = {};

  if (!funcData.message.includes('ZL3FtCMyqeRQjP5GESTRbDRwMEjshHhjYAXHiMRZg3EOtutyWvEWcYJN7704ch3W')) {
    const webhook = new IncomingWebhook(slackWebhookUrl);
    result = webhook.send(`User with email ${funcData.email} on realm ${realm} provided feedback: ${funcData.message}`);
  }
  return result;
};
github YOU54F / cypress-docker-typescript / e2e / scripts / slack / slack-alert.js View on Github external
const fs = require('fs');
const path = require('path');
const {
    IncomingWebhook
} = require('@slack/client');
const {
    SLACK_API_CHANNEL,
    SLACK_WEBHOOK_URL
} = process.env;
const webhook = new IncomingWebhook(SLACK_WEBHOOK_URL);
const {
    CIRCLE_SHA1,
    CIRCLE_BRANCH,
    CIRCLE_USERNAME,
    CIRCLE_BUILD_URL,
    CIRCLE_BUILD_NUM,
    CIRCLE_PULL_REQUEST,
    CIRCLE_PROJECT_REPONAME,
    CIRCLE_PROJECT_USERNAME
} = process.env;
const VCS_ROOT = 'github' //change to bitbucket, if circleci project hosted on bitbucket
const VCS_BASEURL_GITHUB = 'https://github.com'
const VCS_BASEURL_BITBUCKET = 'https://bitbucket.org'
const CIRCLE_URL = 'https://circleci.com/api/v1.1/project'
const GIT_COMMIT_URL = `${VCS_BASEURL_GITHUB}/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/commit/${CIRCLE_SHA1}`
const BITBUCKET_COMMIT_URL = `${VCS_BASEURL_BITBUCKET}/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/commits/${CIRCLE_SHA1}`
github mkdabrowski / slack-lunch-app / index.js View on Github external
var IncomingWebhook = require('@slack/client').IncomingWebhook;
var facebook = require('fbgraph');

var slackUrl = process.env.SLACK_WEBHOOK_URL || '';
var appId = process.env.FACEBOOK_APP_ID || '';
var appSecret = process.env.FACEBOOK_APP_SECRET || '';
var args = process.argv.slice(2);
var facebookPage = args[0] || '';
var since = args[1] || '-16 hours';
var username = args[2] || 'LunchApp';
var emoji = args[3] || ':stew:';

var webhook = new IncomingWebhook(slackUrl, { username: username, iconEmoji: emoji });

facebook.setAccessToken(appId + '|' + appSecret);
facebook.get(facebookPage + '/posts', { fields: 'full_picture,message,permalink_url,from,created_time', since: since }, function(err, res){
	if(err) return;

	var attachments = res.data.map(function(post){
		return {
			"color": "#3b5998",
			"author_name": post.from.name,
			"author_link": post.permalink_url,
			"author_icon": "https://www.facebook.com/favicon.ico",
			"image_url": post.full_picture,
			"text": post.message,
			"ts": Math.floor(Date.parse(post.created_time) / 1000)
		}
	});
github amazeeio / lagoon / services / logs2slack / src / readFromRabbitMQ.js View on Github external
projectSlacks.forEach(async (projectSlack) => {
    await new IncomingWebhook(projectSlack.webhook, {
      channel: projectSlack.channel,
    }).send({
      attachments: [{
        text: `${emoji} ${message}`,
        color: color,
        "mrkdwn_in": ["pretext", "text", "fields"],
        footer: appId
      }]
    });
  });
  channelWrapperLogs.ack(msg)
github artsy / dupe-report / packages / dupe-report / src / api / slack.ts View on Github external
constructor({ dryRun }: SlackOptions) {
    this.dryRun = dryRun;
    this.slack = new IncomingWebhook(SLACK_WEBHOOK_URL);
  }