Google Apps Script를 사용하여 Slack 채널 가입 시 환영 메시지 보내기
9978 단어 슬랙slack-apiGoogleAppsScriptgas
TL;DR
zapier라는 편리한 도구가 있습니다

Slack이라든지 GAS라든지의 버전의 차이로 집착한 경우는 이것을 보면 좋다고 생각합니다.
htps //w w. 요츠베. 이 m/와 tch? v = 요 HsH8 Ang
완성형

참고
Slack API 공식 doc
Slack의 EventAPI와 GAS를 이용해 특정 채널에 join하면 welcome 메시지를 표시하는 Bot을 만들어 보았다
Slack Bot을 GAS로 좋은 느낌으로 쓰는 라이브러리를 만들었습니다.
해줘.
슬랙 앱 만들기
"Create New App"을 클릭하고 "App Name", "Development Slack Workspace"를 입력합니다.

Bot User 만들기
사이드바에서 "Bot Users"를 선택하고 "Add a Bot User"를 클릭합니다.
파라미터는 그대로 "Add Bot User"로 OK.

이 화면은 열린 상태로 둡니다.
Google Apps Script(GAS) 만들기
Google 드라이브를 열고 신규 > 기타 > Google Apps Script를 선택합니다.
다른 곳에 Google Apps Script가 없으면 "앱 추가"에서 연결하십시오.
일단 밸리데이션용의 코드를 기술한다.
코드.js
function doPost(e){
var params = JSON.parse(e.postData.getDataAsString());
return ContentService.createTextOutput(params.challenge);
}
function doGet(e){
doPost(e);
}
GAS 공개

반드시 프로젝트 버전은 New, 애플리케이션에 액세스할 수 있는 사용자에게는 모두(익명 사용자 포함)를 선택하는 것.
2번째 이후는 프로젝트가 갱신되지 않거나 Slack에서 GAS를 실행할 수 없게 되거나 한다.
Event Subscriptions 설정
이것이 나오지 않으면 뭔가 이상하기 때문에 검토하십시오.

GAS 변경
코드.js
function doPost(e){
var token = PropertiesService.getScriptProperties().getProperty('SLACK_ACCESS_TOKEN');
var slackApp = SlackApp.create(token);
var params = JSON.parse(e.postData.getDataAsString());
var channelId = params.event.channel;
var userId = params.event.user;
var options = {
channelId: channelId, // 参加したチャンネルのID、 #test などのチャンネル名でも投稿可能
userName: "Welcome Bot", // 投稿するbotの名前
message: "<@" + userId + "> Welcome!!! :zany_face:", // 投稿するメッセージ
};
slackApp.postMessage(options.channelId, options.message, {username: options.userName});
}
function doGet(e){
doPost(e);
}
SlackApp 라이브러리 추가
M3W5Ut3Q39AaIwLquryEPMwV62A3znfOO
추가 및 저장 
SLACK_ACCESS_TOKEN 설정
GAS 내에
var token = PropertiesService.getScriptProperties().getProperty('SLACK_ACCESS_TOKEN');
라고 써 있지만, 지금 그대로는 SLACK_ACCESS_TOKEN을 취득할 수 없기 때문에 설정한다.


실행해보기
응용 프로그램을 채널로 부르는 것이 좋습니다.

Tips
Slack의 channelId는 브라우저에서 열면 확인할 수 있다(messages/뒤의 문자열)

Reference
이 문제에 관하여(Google Apps Script를 사용하여 Slack 채널 가입 시 환영 메시지 보내기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/hondy12345/items/0cdc81bb2170cbdb54ec텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)