質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

Slack

Slackは、Tiny Speckという企業からリリースされたコミュニケーションツールです。GoogleDriveやGitHubなど、さまざまな外部サービスと連携することができます。

Q&A

解決済

1回答

736閲覧

Slackでダイアログを表示するが送信後に閉じられない

ices_sinon

総合スコア479

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

Slack

Slackは、Tiny Speckという企業からリリースされたコミュニケーションツールです。GoogleDriveやGitHubなど、さまざまな外部サービスと連携することができます。

0グッド

0クリップ

投稿2019/06/17 07:25

SlackでDialogをだしたのですが、送信ボタンを押しても再試行してくださいとでてしまいます。送信を押すたびにsubmissionにDialogの情報が与えられるので、Dialogを閉じたいのですが参考の意見がいただきたいです。

nodo

1require('dotenv').config(); 2const { WebClient } = require('@slack/client') 3const token = process.env.SLACK_CLIENT_TOKEN 4const web = new WebClient(token) 5const conversationId = 'general' 6 7const attachments = [ 8 { 9 fallback: 'アンケートです', 10 callback_id: "oyatu", 11 actions: [ 12 { 13 name: "oyatu_list", 14 // セレクトボックスの初期テキスト 15 text: "セレクト?", 16 // typeをselectに 17 type: "select", 18 // optionsを追加 19 options: [ 20 { 21 text: '書籍', 22 value: 'apple' 23 }, 24 ] 25 } 26 ] 27 } 28] 29 30const option = { 31 attachments: attachments, 32 channel: conversationId, 33 icon_emoji: ':question:', 34 username: 'Book-put' 35} 36 37web.chat.postMessage(option) 38 .then(res => { 39 console.log('書籍を投稿しました。 ', res.ts) 40 }) 41 .catch(console.error)

nodo

1require('dotenv').config(); 2 3const express = require("express") 4const app = express() 5const bodyParser = require('body-parser') 6const urlencodedParser = bodyParser.urlencoded({ extended: false }) 7 8// Web API関連 9const { WebClient } = require('@slack/client') 10const token = process.env.NDE_TOKEN 11const web = new WebClient(token) 12 13app.post('/', urlencodedParser, function (req, res) { 14 const payload = JSON.parse(req.body.payload) 15 console.log(payload) 16 17 switch (payload.type) { 18 // interactive_messageを受け取った時の処理 19 case 'interactive_message': 20 // dialog.openメソッドでダイアログを展開 21 web.dialog.open({ 22 dialog: { 23 // ダイアログの設定 24 callback_id: "dialog", 25 title: "書籍投稿", 26 submit_label: "送信します", 27 notify_on_cancel: true, 28 // フォームの設定 29 elements: [ 30 { 31 type: "text", 32 label: "名前", 33 name: "name", 34 hint: "お名前を入力してください", 35 placeholder: '題材名' 36 }, 37 { 38 type: "text", 39 subtype: "email", 40 label: "メールアドレス", 41 name: "email", 42 placeholder: "example@email.com", 43 }, 44 { 45 type: "text", 46 subtype: "tel", 47 label: "電話番号", 48 name: "tel", 49 placeholder: "123-4567", 50 }, 51 { 52 label: "評価", 53 type: "select", 54 name: "review", 55 optional: "true", 56 options: [ 57 { 58 label: "すごく良い", 59 value: "very_good" 60 }, 61 { 62 label: "良い", 63 value: "good" 64 }, 65 { 66 label: "普通", 67 value: "normal" 68 }, 69 { 70 label: "悪い", 71 value: "bad" 72 }, 73 { 74 label: "すごく悪い", 75 value: "very_bad" 76 } 77 ] 78 }, 79 { 80 type: "textarea", 81 label: "その他", 82 name: "others", 83 hint: "好きに書いてください", 84 optional: "true" 85 } 86 ] 87 }, 88 // payloadにあるtrigger_idをトリガーIDに指定 89 trigger_id: payload.trigger_id 90 }) 91 .then(() => { 92 console.log('ダイアログを送信しました') 93 }) 94 .catch(console.error) 95 res.status(200).end() 96 97 break 98 // dialog_submissionを受け取った時の処理 99 case 'dialog_submission': 100 console.log('ダイアログの結果を受信しました') 101 102 // メールアドレス判定用の正規表現 103 const re = { 104 email: /^(([^<>()[]\.,;:\s@"]+(.[^<>()[]\.,;:\s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z\-0-9]+.)+[a-zA-Z]{2,}))$/, 105 } 106 // メールアドレスの形式が正しくなかったらエラー 107 if (re.email.test(payload.submission.email) === false) { 108 // json形式で送信するとSlackに反映される 109 res.setHeader('Content-Type', 'application/json') 110 111 res.send({ 112 "errors": [ 113 { 114 "name": "email", 115 "error": "メールアドレスの形式が正しくありません" 116 } 117 ] 118 }) 119 } 120 } 121}) 122 123app.listen(3000)

![Dialog

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

送信後に正常なレスポンスをSlack側に返さないと、Dialogが閉じられないです!

dialog_submission

の処理の中でも一度status200を返してみても同じでしょうか。

SlackのDocumentを確認してみたところ、

Upon receiving this payload, your server must respond within 3 seconds,

とありましたが、Submissionのレスポンスは3秒以内に返してますでしょうか。

投稿2019/06/17 12:36

tail12

総合スコア607

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ices_sinon

2019/06/17 23:42

ありがとうございます!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問