How to use @slack/webhook - 10 common examples

To help you get started, we’ve selected a few @slack/webhook 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 seratch / slack-app-examples / serverless-gcp-template / index.js View on Github external
.then(handleApiResponse)
            .catch(handleApiError)

        } else if (payload.event.text.match('42')) {
          // use chat.postMessage over say method
          slackWebApi.chat.postMessage({
            channel: payload.event.channel,
            text: 'The answer to life, the universe and everything',
            thread_ts: payload.event.ts
          })
            .then(handleApiResponse)
            .catch(handleApiError)

        } else if (payload.event.text.match('webhook')) {
          const url = process.env.SLACK_WEBHOOK_URL;
          const webhook = new IncomingWebhook(url);
          webhook.send({
            text: payload.event.text.split("webhook")[1],
            unfurl_links: true
          })
            .then((apiRes) => {
              console.log(`Succeeded ${JSON.stringify(apiRes)}`)
            }).catch(reason => {
              console.error(`Failed because ${reason}`)
            })
        }
      }
    }

  } else {
    // application/x-www-form-urlencoded
    const qs = require('querystring')
github mooyoul / melon-ticket-actions / index.js View on Github external
var _a;
    // Validate parameters
    const [productId, scheduleId, seatId, webhookUrl] = [
        "product-id",
        "schedule-id",
        "seat-id",
        "slack-incoming-webhook-url",
    ].map((name) => {
        const value = core.getInput(name);
        if (!value) {
            throw new Error(`melon-ticket-actions: Please set ${name} input parameter`);
        }
        return value;
    });
    const message = (_a = core.getInput("message"), (_a !== null && _a !== void 0 ? _a : "티켓사세요"));
    const webhook = new webhook_1.IncomingWebhook(webhookUrl);
    const res = await axios_1.default({
        method: "POST",
        url: "https://ticket.melon.com/tktapi/product/seatStateInfo.json",
        params: {
            v: "1",
        },
        data: qs.stringify({
            prodId: productId,
            scheduleNo: scheduleId,
            seatId,
            volume: 1,
            selectedGradeVolume: 1,
        }),
    });
    // tslint:disable-next-line
    console.log("Got response: ", res.data);
github elastic / kibana / x-pack / legacy / plugins / actions / server / builtin_action_types / slack.ts View on Github external
async function slackExecutor(
  execOptions: ActionTypeExecutorOptions
): Promise {
  const id = execOptions.id;
  const secrets = execOptions.secrets as ActionTypeSecretsType;
  const params = execOptions.params as ActionParamsType;

  let result: IncomingWebhookResult;
  const { webhookUrl } = secrets;
  const { message } = params;

  try {
    const webhook = new IncomingWebhook(webhookUrl);
    result = await webhook.send(message);
  } catch (err) {
    if (err.original == null || err.original.response == null) {
      return errorResult(id, err.message);
    }

    const { status, statusText, headers } = err.original.response;

    // special handling for 5xx
    if (status >= 500) {
      return retryResult(id, err.message);
    }

    // special handling for rate limiting
    if (status === 429) {
      return pipe(
github seratch / slack-app-examples / bolt-gcp-js-template / app.js View on Github external
app.message('webhook', ({ message }) => {
  const { IncomingWebhook } = require('@slack/webhook');
  const url = config.SLACK_WEBHOOK_URL;
  const webhook = new IncomingWebhook(url);
  webhook.send({
    text: message.text.split("webhook")[1],
    unfurl_links: true
  })
    .then((res) => {
      console.log(`Succeeded ${JSON.stringify(res)}`)
    }).catch(reason => {
      console.error(`Failed because ${reason}`)
    })
})
github seratch / slack-app-examples / bolt-serverless-aws-template / aws-ts / app.ts View on Github external
app.message('webhook', ({ message }) => {
  const { IncomingWebhook } = require('@slack/webhook');
  const url = process.env.SLACK_WEBHOOK_URL;
  const webhook = new IncomingWebhook(url);
  webhook.send({
    text: message.text.split("webhook")[1],
    unfurl_links: true
  })
    .then((res) => {
      console.log(`Succeeded ${JSON.stringify(res)}`)
    }).catch(reason => {
      console.error(`Failed because ${reason}`)
    })
})
github devcon-london / website / functions / slack.js View on Github external
exports.notifySlack = (msg) => {
  const url = functions.config().slack_integration.webhook_url;
  const webhook = new IncomingWebhook(url, {});

  return webhook
    .send({
      text: msg,
    })
    .then(() => {
      console.log('notification sent');
    })
    .catch((e) => {
      console.log('error while posting to slack', e);
    });
};
github IBM / taxinomitis / src / lib / notifications / slack.ts View on Github external
export function init() {
    const slackUrl: string | undefined = process.env[env.SLACK_WEBHOOK_URL];
    if (slackUrl) {
        webhook = new IncomingWebhook(slackUrl);
    }
}
github mooyoul / melon-ticket-actions / index.ts View on Github external
"product-id",
    "schedule-id",
    "seat-id",
    "slack-incoming-webhook-url",
  ].map((name) => {
    const value = core.getInput(name);
    if (!value) {
      throw new Error(`melon-ticket-actions: Please set ${name} input parameter`);
    }

    return value;
  });

  const message = core.getInput("message") ?? "티켓사세요";

  const webhook = new IncomingWebhook(webhookUrl);

  const res = await axios({
    method: "POST",
    url: "https://ticket.melon.com/tktapi/product/seatStateInfo.json",
    params: {
      v: "1",
    },
    data: qs.stringify({
      prodId: productId,
      scheduleNo: scheduleId,
      seatId,
      volume: 1,
      selectedGradeVolume: 1,
    }),
  });
github treosh / lighthouse-ci-action / src / output.js View on Github external
async function slackNotification({ status, slackWebhookUrl }) {
  const conclusion = status === 0 ? 'success' : 'failure'
  const webhook = new IncomingWebhook(slackWebhookUrl)
  const color = status === 0 ? 'good' : 'danger'

  /** @type {Buffer} */
  const assertionResults = readFileSync(`${process.cwd()}/.lighthouseci/assertion-results.json`)
  const groupedResults = groupBy(JSON.parse(assertionResults.toString()), 'url')

  const attachments = Object.values(groupedResults).map(groupedResult => {
    const results = groupedResult.map(
      /**
       * @param {{auditId: string, auditProperty: string, auditTitle: string, expected: string, operator: string, actual: string, url: string}} res
       * @return {{title?: string, type: string, value: string, url: string}}
       */
      res => ({
        title: `${res.auditId}.${res.auditProperty}`,
        value: `${res.auditTitle} \n _Expected ${res.expected} ${
          res.operator === '<=' ? ' less then' : ' greater than'
github YOU54F / cypress-docker-typescript / e2e / scripts / slack / slack-alert.ts View on Github external
const webhookInitialArguments = webhookInitialArgs({}, status);
      const webhook = new IncomingWebhook(
        SLACK_WEBHOOK_URL,
        webhookInitialArguments
      );
      const reports = attachmentReports({
        attachmentsReports: attachments,
        status
      });
      const artefacts = attachementsVideoAndScreenshots(attachments, status);
      const sendArguments = webhookSendArgs(sendArgs, [reports, artefacts]);
      return webhook.send(sendArguments);
    }
    case "passed": {
      const webhookInitialArguments = webhookInitialArgs({}, status);
      const webhook = new IncomingWebhook(
        SLACK_WEBHOOK_URL,
        webhookInitialArguments
      );
      const reports = attachmentReports({
        attachmentsReports: attachments,
        status
      });
      const artefacts = attachementsVideoAndScreenshots(attachments, status);
      const sendArguments = webhookSendArgs(sendArgs, [reports, artefacts]);
      return webhook.send(sendArguments);
    }
    default: {
      throw new Error("An error occured getting the status of the test run");
    }
  }
}

@slack/webhook

Official library for using the Slack Platform's Incoming Webhooks

MIT
Latest version published 4 months ago

Package Health Score

98 / 100
Full package analysis

Popular @slack/webhook functions