実現したいこと
- 外部からの HTTP POSTリクエストにより、Google Chatを投稿したい
- インタラクティブなカードで、送信ボタンを押されると管理者がその情報を収集できる
前提
Google WorkSpace、 GCPを契約しており、プロジェクト設定、Google Chat APIをON、
GASの設定画面でGCPプロジェクトを設定しており、該当GASはGCPのログエクスプローラーで確認できる状態です。
GASコードはデプロイ済み、全員アクセスできる状態で、デプロイIDをGoogle Chat APIに登録してます。
マニフェストファイルは下記の通りです。
{ "timeZone": "Asia/Tokyo", "dependencies": {}, "exceptionLogging": "STACKDRIVER", "runtimeVersion": "V8", "chat": {}, "webapp": { "executeAs": "USER_DEPLOYING", "access": "ANYONE_ANONYMOUS" }, "oauthScopes": [ "https://www.googleapis.com/auth/script.external_request" ] }
試した事
大きく分けて、二通りの方法を試みました
<1>
Google Chat BotをGASで構築し、doPost関数でHTTP POSTを受け取ったら、
onMessage(event)を発火する。
→失敗
(event)の中身を実際に投稿された時と同じ様に設定して、
onMessage(event)にメッセージのJSONを戻しても、そのメッセージは投稿されませんでした。
<2>
Webhookで指定スペースにカードを投稿し、そのカードのボタンに"action":{"function":"submitForm"}を設定し、
送信ボタンをクリックした時に該当関数を発火させる。
→失敗
カード自体は生成出来て、送信ボタンをクリックするとローディングっぽい挙動になりますが、
実際はトリガーされておりませんでした。GASが起動した形跡が無い。
カードのログを確認する方法を思いつかない為、八方塞がり状態です。
どなたかご教授いただきたいです。
どうかよろしくお願いいたします。
該当のソースコード
※方法<2>についてのコードです。
※function submitForm(event)がそもそもトリガーされない為、このGASコードの中身は適当です。
gs
1function submitForm(event) { 2 // Get the user input and other data from the event object 3 var name = event.formInput.name; 4 var email = event.formInput.email; 5 var actionMethodName = event.action.actionMethodName; 6 var parameters = event.action.parameters; 7 8 console.log(event) 9 10 // Create a confirmation message to return to Google chat 11 var message = "Thank you for submitting your name and email address."; 12 13 // Create a text paragraph widget with the confirmation message 14 var textParagraph = CardService.newTextParagraph() 15 .setText(message); 16 17 // Create a section with the text paragraph widget 18 var section = CardService.newCardSection() 19 .addWidget(textParagraph); 20 21 // Create a card with the section 22 var card = CardService.newCardBuilder() 23 .addSection(section) 24 .build(); 25 26 // Return the card as an update to the existing card 27 return CardService.newUpdateCardAction() 28 .setCard(card); 29}
※これをMakeからHTTP POSTで送信してます。カード自体は正常に投稿されます。
JSON
1{ 2 "cardsV2": [ 3 { 4 "cardId": "unique-card-id", 5 "card": { 6 "header": { 7 "title": "Sasha", 8 "subtitle": "Software Engineer", 9 "imageUrl": "https://developers.google.com/chat/images/quickstart-app-avatar.png", 10 "imageType": "CIRCLE", 11 "imageAltText": "Avatar for Sasha" 12 }, 13 "sections": [ 14 { 15 "header": "内容", 16 "widgets": [ 17 { 18 "textParagraph": { 19 "text": "FAX電話番号: <b>03-1234-5678</b>" 20 } 21 }, 22 { 23 "selectionInput": { 24 "label": "対応する部署を選択してください", 25 "name": "department", 26 "type": "DROPDOWN", 27 "items": [ 28 { 29 "text": "未分類", 30 "value": "Uncategorized" 31 }, 32 { 33 "text": "経理", 34 "value": "accounting" 35 }, 36 { 37 "text": "購買", 38 "value": "purchasing" 39 }, 40 { 41 "text": "物件情報", 42 "value": "property" 43 }, 44 { 45 "text": "DM", 46 "value": "dm" 47 } 48 ] 49 } 50 }, 51 { 52 "textInput": { 53 "name": "name", 54 "label": "業者名を入力してください" 55 } 56 }, 57 { 58 "divider": {} 59 }, 60 { 61 "buttonList": { 62 "buttons": [ 63 { 64 "text": "送信", 65 "onClick": { 66 "action": { 67 "function": "submitForm", 68 "parameters": { 69 "key": "string", 70 "value": "value" 71 } 72 } 73 } 74 } 75 ] 76 } 77 } 78 ] 79 } 80 ] 81 } 82 } 83 ] 84}

あなたの回答
tips
プレビュー