Last active
August 31, 2024 12:53
-
-
Save okash1n/44ccb0fb6795378cbcc96f07188549e3 to your computer and use it in GitHub Desktop.
Slackで誰かに送った自分のDMを全部消すやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function deleteDMsByChannelId() { | |
const token = 'slack_api_token'; // Slack APIのUserトークン(xoxp-)を設定 | |
const channel_id = 'im_id'; // 削除するダイレクトメッセージのチャンネルID(DMの中のメッセージのリンクの「archive/****」の部分)を設定 | |
const api_endpoint = 'https://slack.com/api/conversations.history?channel=' + channel_id; | |
// DMのメッセージ履歴を取得 | |
const response = UrlFetchApp.fetch(api_endpoint, { | |
'headers': { | |
'Authorization': 'Bearer ' + token | |
} | |
}); | |
const data = JSON.parse(response.getContentText()); | |
const messages = data.messages; | |
// DM内の全ての自分が送ったメッセージを削除 | |
for (let j = 0; j < messages.length; j++) { | |
const ts = messages[j].ts; | |
const api_endpoint = 'https://slack.com/api/chat.delete?channel=' + channel_id + '&ts=' + ts; | |
const response = UrlFetchApp.fetch(api_endpoint, { | |
'headers': { | |
'Authorization': 'Bearer ' + token | |
} | |
}); | |
// APIのレート制限エラーを回避するためのウェイトを追加 | |
Utilities.sleep(1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DMだけを消す場合Scopeは以下でOK
