Last active
October 22, 2021 05:26
-
-
Save FromAtom/e429d31ee94edc8e73fccc9aa0db9558 to your computer and use it in GitHub Desktop.
This file contains 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
# | |
# ENV["ESA_POST_NUMBER"]: 更新するesa記事の番号. | |
# ENV["SLACK_OAUTH_ACCESS_TOKEN"]: SlackのAccessToken. `channels:read` 権限が必要. | |
# ENV['ESA_API_TOKEN']: esaのtoken. write権限が必要. | |
# ENV['ESA_TEAM']: esaのteam名. | |
# ENV['SLACK_TEAM_NAME']: https://TEAM_NAME.slack.com の TEAM_NAME部分 | |
# | |
require 'slack-ruby-client' | |
require 'esa' | |
# 全チャンネルを取得する | |
Slack.configure do |config| | |
config.token = ENV["SLACK_OAUTH_ACCESS_TOKEN"] | |
end | |
slack_client = Slack::Web::Client.new | |
all_channels = [] | |
slack_client.conversations_list(exclude_archived: true, limit: 1000, sleep_interval: 1, max_retries: 20) do |response| | |
all_channels.concat(response.channels) | |
end | |
# esa用に加工 | |
markdown_text_buffer = [] | |
markdown_text_buffer << <<-EOS | |
# 概要 | |
このesaは、 `#{ENV['SLACK_TEAM_NAME']}.slack.com` のパブリックチャンネル一覧です。 | |
:chart_with_upwards_trend: **現在のチャンネル数:#{all_channels.length}** | |
# 一覧 | |
EOS | |
all_channels.sort_by(&:name).each do |c| | |
id = c.id | |
url = "https://#{ENV['SLACK_TEAM_NAME']}.slack.com/archives/#{id}" | |
name = c.name | |
purpose = c.purpose.value | |
topic = c.topic.value | |
num_members = c.num_members | |
markdown_text_buffer << <<-EOS | |
## [##{name}](#{url})|:busts_in_silhouette: #{num_members} | |
#### 目的 | |
``` | |
#{purpose} | |
``` | |
#### トピック | |
``` | |
#{topic} | |
``` | |
EOS | |
end | |
md_text = markdown_text_buffer.join("\n") | |
# esaに書き込む | |
esa_client = Esa::Client.new(access_token: ENV['ESA_API_TOKEN'], current_team: ENV['ESA_TEAM']) | |
esa_client.update_post( | |
ENV["ESA_POST_NUMBER"], | |
wip: false, | |
updated_by: 'esa_bot', # owner権限がないとesa_botは指定できません ref.https://docs.esa.io/posts/102#PATCH%20/v1/teams/:team_name/posts/:post_number | |
message: '[skip notice]', | |
body_md: md_text | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment