Help us understand the problem. What is going on with this article?

Incoming Webhookとjavascriptでslackに送信する

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)
  })
}

giftpad
ギフトカードで幸せを届ける!世界を笑顔にするベンチャー企業
https://giftpad.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away