2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Incoming Webhookとjavascriptでslackに送信する

Last updated at Posted at 2020-03-16

slackアプリでIncoming Webhookを追加する。
するとWebhook URLが手に入る。

sendSlack () {
  const payload = {
    // slackのデータ
    'blocks': [
      {
        'type': 'section',
        'text': {
          'type': 'mrkdwn',
          'text': 'slackに送信'
        }
      },
      {
        'type': 'section',
        'fields': [
          {
            'type': 'mrkdwn',
            'text': 'ああああ'
          },
        ]
      },
      {
        'type': 'actions',
        'elements': [
          {
            'type': 'button',
            'text': {
              'type': 'plain_text',
              'emoji': true,
              'text': 'Approve'
            },
            'style': 'primary',
            'value': 'click_me_123'
          },
          {
            'type': 'button',
            'text': {
              'type': 'plain_text',
              'emoji': true,
              'text': 'Deny'
            },
            'style': 'danger',
            'value': 'click_me_123'
          }
        ]
      }
    ]
  }

  const _self = this
  const url = 'https://hooks.slack.com/services/{token}'

  fetch(url, {
    method: 'POST',
    body: JSON.stringify(payload)
  }).then(function (responce) {
    if (!responce.ok) {
      alert('エラーです')
    }
    _self.$router.push('/')
  }).catch(function (error) {
    console.log(error.message)
  })
}

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?