그 버튼으로 호출 버튼 해봤어요.
원자재
https://twitter.com/JICRochelle/status/1062842367105884162
리트윗이 없네요.
이걸 봤을 때부터 SORACOM IoT Buton이 완성할 수 있을 것 같아서 해봤어요.
구조
슬랙 채널에서 파티션을 건너뛰고 호출을 받습니다.(맞아, 마지막 마일은 사람이야.)
# 소스 파일
소스 자체가 지난번에 만든 것과 거의 같다.
index.js
'use strict'
const request = require('request');
const AWS = require('aws-sdk');
AWS.config.update({ region: 'ap-northeast-1' });
const kms = new AWS.KMS();
const encryptedSlackWebHookUrl = process.env['SLACK_WEBHOOK_URL'];
let decryptedSlackWebHookUrl;
/**
* 初期化
* @param {[type]} event [description]
* @param {[type]} context [description]
* @return {[type]} [description]
*/
const initialize = (event, context) => {
return new Promise((resolve) => {
let message = ''
if (event.deviceEvent.buttonClicked.clickType == "SINGLE") {
message = process.env['CALLING_MESSAGE_SINGLE'];
} else if (event.deviceEvent.buttonClicked.clickType == "DOUBLE") {
message = process.env['CALLING_MESSAGE_DOUBLE'];
} else {
message = process.env['CALLING_MESSAGE_LONG'];
}
const stash = {
clickType: event.deviceEvent.buttonClicked.clickType,
message,
};
console.log(stash);
resolve(stash);
});
};
/**
* Slack WebHook URL情報復号処理
* @param {[type]} stash [description]
* @return {[type]} [description]
*/
const decryptedUrl = (stash) => {
return new Promise((resolve, reject) => {
if (!decryptedSlackWebHookUrl) {
kms.decrypt({ CiphertextBlob: new Buffer(encryptedSlackWebHookUrl, 'base64') }, (err, data) => {
if (err) {
console.log('Decrypt error:', err);
reject(err);
}
decryptedSlackWebHookUrl = data.Plaintext.toString('ascii');
resolve(stash);
});
} else {
resolve(stash);
}
});
};
/**
* Slack POST
* @param {[type]} stash [description]
* @return {[type]} [description]
*/
const postSlackMessage = (stash) => {
return new Promise((resolve, reject) => {
console.log('slack Call');
// リクエスト設定
const options = {
url: decryptedSlackWebHookUrl,
headers: {
'Content-type': 'application/json'
},
body: {
"text": stash.message
},
json: true
};
// メッセージ送信
request.post(options, function(error, response, body) {
if (!error && response.statusCode == 200) {
resolve(stash);
} else {
if (error) {
console.log('Slack API Error: ' + error);
reject(error);
} else {
console.log('Slack API Error: ' + response.statusCode);
const err = {
'statusCode': response.statusCode
}
reject(err);
}
}
});
});
};
/**
* Main処理
* @param {[type]} event [description]
* @param {[type]} context [description]
* @param {Function} callback [description]
* @return {[type]} [description]
*/
exports.handler = (event, context, callback) => {
initialize(event, context)
.then(decryptedUrl)
.then(postSlackMessage)
.then(callback.bind(null, null))
.catch(callback);
};
메시지는 버튼 형식에 따라 환경 변수로 설정됩니다.(Lambda의 환경 변수, 일본어가 있네. 내가 보통 안에 넣어봤는데 아주 보통 w)
환경 변수

싱글 클릭(벗어나고 싶을 때)

더블 클릭(당장 빠져나가고 싶을 때)

길게 누르기(헤어나지 못하거나 회의에 계속 참가하기로 결정한 경우)

금후
확실히, 자동으로 전화가 왔으면 좋겠어요.
참고 자료
Slack의 Incoming Webhooks로 멤버 메시지를 보내는 방법
Reference
이 문제에 관하여(그 버튼으로 호출 버튼 해봤어요.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/keni_w/items/b29aee5a7f65c075557f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)