###できていること
Slackにボタン付きメッセージをbotで送ることはできています。
加えて、"/hogehoge"を送信すると、ダイアログが立ち上がり、入力できるところまでもできています。
使っている機能は以下です。
- Google Apps Script
- Incoming Webhooks
- Slack API
- Slash Command
###現段階のコード
javascript
1//Slash Comandを受信 2function doPost(e){ 3 var response = send_Button(e); 4 return ContentService.createTextOutput(JSON.stringify(response)).setMimeType(ContentService.MimeType.JSON); 5} 6 7function send_Button(e) { 8 var input_text = e.parameter.text; 9 var slackUrl = "https://hooks.slack.com/services/xxxxx.....xxxxxxx"; 10 // message text 11 var messageData = { 12 "text":"subject:"+input_text, 13 "attachments": [ 14 { 15 "text": "Are you ok?", 16 "fallback": "Sorry, no support for buttons.", 17 "callback_id": "lessonbutton", 18 "color": "#3AA3E3", 19 "attachment_type": "default", 20 "actions": [ 21 { 22 "name": "button", 23 "text": "OK", 24 "style": "primary", 25 "type": "button", 26 "value": "ok" 27 }] 28 }] 29} 30 31 32// format for Slack 33var options = { 34 'method' : 'post', 35 'contentType': 'application/json', 36 // Convert the JavaScript object to a JSON string. 37 'payload' : JSON.stringify(messageData) 38}; 39 40// post to Slack 41UrlFetchApp.fetch(slackUrl, options); 42return input_text; 43}
すると、Slackにボタン付きInteractive Messageが届きます。
javascript
1function Slack_Dialog(e) { 2 var text = e.parameter.text; 3 var response = {text: text}; 4 var trigger_id = e.parameter.trigger_id; 5 var slackUrl = "https://hogehogehoge.slack.com/api/dialog.open"; 6 var dialog = { 7 "token": "xoxxxxxxxxxxxxxxxxxxxxxxxxxxxxx....xxxx", 8 "trigger_id": trigger_id, 9 "dialog": JSON.stringify({ 10 "callback_id": "wantdo3", 11 "title": "What do you want to do there?", 12 "submit_label": "Request", 13 "elements": [ 14 { 15 "type": "text", 16 "label": "In The Morning", 17 "name": "dialg_morning" 18 }, 19 { 20 "type": "text", 21 "label": "In The Afternoon", 22 "name": "dialg_afternoon" 23 }, 24 { 25 "type": "text", 26 "label": "In The Night", 27 "name": "dialg_night" 28 } 29 ] 30 }) 31 } 32 var options = { 33 'method' : 'post', 34 'payload' : dialog, 35 }; 36 return response = UrlFetchApp.fetch(slackUrl, options); 37} 38
すると、ダイアログが開きます。
###やりたいこと
"/hogehoge"と入力すると、ボタン付きメッセージが送られてきて、ボタンを押すとダイアログが立ち上がるようにしたい。
https://www.slideshare.net/yasuyuki_ogawa/slack-apps
こちらのリンクのスライド(p14)にコールバックが大事云々とありました。
しかし、当方、まだコールバックを理解しておりません。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー