Class: SlackBot::ApiClient
- Inherits:
-
Object
- Object
- SlackBot::ApiClient
- Defined in:
- lib/slack_bot/api_client.rb,
sig/slack_bot.rbs
Constant Summary collapse
- SLACK_API_BASE_URL =
Slack API base URL
"https://slack.com/api/"- REQUEST_TIMEOUT =
Request timeout in seconds
30- CONNECTION_TIMEOUT =
Connection timeout in seconds
10- TOKEN_FORMAT =
/\Axox[bpa]-/
Instance Attribute Summary collapse
-
#client ⇒ Faraday::Connection
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #chat_delete(channel:, ts:) ⇒ ApiResponse
- #chat_delete_scheduled_message(channel:, scheduled_message_id:) ⇒ ApiResponse
- #chat_get_permalink(channel:, message_ts:) ⇒ ApiResponse
- #chat_post_ephemeral(channel:, user:, text:, as_user: nil, attachments: nil, blocks: nil, icon_emoji: nil, icon_url: nil, link_names: nil, parse: nil, thread_ts: nil, username: nil) ⇒ ApiResponse
- #chat_post_message(channel:, text:, blocks:) ⇒ ApiResponse
- #chat_schedule_message(channel:, text:, post_at:, blocks: nil) ⇒ ApiResponse
- #chat_unfurl(channel:, ts:, unfurls:, source: nil, unfurl_id: nil, user_auth_blocks: nil, user_auth_message: nil, user_auth_required: nil, user_auth_url: nil) ⇒ ApiResponse
- #chat_update(channel:, ts:, text:, blocks:) ⇒ ApiResponse
-
#initialize(authorization_token: ) ⇒ ApiClient
constructor
A new instance of ApiClient.
- #scheduled_messages_list(channel: nil, cursor: nil, latest: nil, limit: nil, oldest: nil, team_id: nil) ⇒ ApiResponse
- #users_info(user_id:) ⇒ ApiResponse
- #users_list(cursor: nil, limit: 200, include_locale: nil, team_id: nil) ⇒ ApiResponse
- #views_open(trigger_id:, view:) ⇒ ApiResponse
- #views_publish(user_id:, view:) ⇒ ApiResponse
- #views_update(view_id:, view:) ⇒ ApiResponse
Constructor Details
#initialize(authorization_token: ) ⇒ ApiClient
Returns a new instance of ApiClient.
70 71 72 73 |
# File 'lib/slack_bot/api_client.rb', line 70 def initialize(authorization_token: ENV["SLACK_BOT_API_TOKEN"]) () @client = build_client() end |
Instance Attribute Details
#client ⇒ Faraday::Connection (readonly)
Returns the value of attribute client.
68 69 70 |
# File 'lib/slack_bot/api_client.rb', line 68 def client @client end |
Instance Method Details
#chat_delete(channel:, ts:) ⇒ ApiResponse
91 92 93 |
# File 'lib/slack_bot/api_client.rb', line 91 def chat_delete(channel:, ts:) perform_request { client.post("chat.delete", {channel: channel, ts: ts}.to_json) } end |
#chat_delete_scheduled_message(channel:, scheduled_message_id:) ⇒ ApiResponse
120 121 122 |
# File 'lib/slack_bot/api_client.rb', line 120 def (channel:, scheduled_message_id:) perform_request { client.post("chat.deleteScheduledMessage", {channel: channel, scheduled_message_id: }.to_json) } end |
#chat_get_permalink(channel:, message_ts:) ⇒ ApiResponse
124 125 126 |
# File 'lib/slack_bot/api_client.rb', line 124 def chat_get_permalink(channel:, message_ts:) perform_request { client.post("chat.getPermalink", {channel: channel, message_ts: }.to_json) } end |
#chat_post_ephemeral(channel:, user:, text:, as_user: nil, attachments: nil, blocks: nil, icon_emoji: nil, icon_url: nil, link_names: nil, parse: nil, thread_ts: nil, username: nil) ⇒ ApiResponse
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/slack_bot/api_client.rb', line 141 def chat_post_ephemeral(channel:, user:, text:, as_user: nil, attachments: nil, blocks: nil, icon_emoji: nil, icon_url: nil, link_names: nil, parse: nil, thread_ts: nil, username: nil) args = compact_payload( channel: channel, user: user, text: text, as_user: as_user, attachments: , blocks: blocks, icon_emoji: icon_emoji, icon_url: icon_url, link_names: link_names, parse: parse, thread_ts: thread_ts, username: username ) perform_request { client.post("chat.postEphemeral", args.to_json) } end |
#chat_post_message(channel:, text:, blocks:) ⇒ ApiResponse
83 84 85 |
# File 'lib/slack_bot/api_client.rb', line 83 def (channel:, text:, blocks:) perform_request { client.post("chat.postMessage", {channel: channel, text: text, blocks: blocks}.to_json) } end |
#chat_schedule_message(channel:, text:, post_at:, blocks: nil) ⇒ ApiResponse
111 112 113 |
# File 'lib/slack_bot/api_client.rb', line 111 def (channel:, text:, post_at:, blocks: nil) perform_request { client.post("chat.scheduleMessage", {channel: channel, text: text, post_at: post_at, blocks: blocks}.to_json) } end |
#chat_unfurl(channel:, ts:, unfurls:, source: nil, unfurl_id: nil, user_auth_blocks: nil, user_auth_message: nil, user_auth_required: nil, user_auth_url: nil) ⇒ ApiResponse
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/slack_bot/api_client.rb', line 95 def chat_unfurl(channel:, ts:, unfurls:, source: nil, unfurl_id: nil, user_auth_blocks: nil, user_auth_message: nil, user_auth_required: nil, user_auth_url: nil) perform_request do client.post("chat.unfurl", { channel: channel, ts: ts, unfurls: unfurls, source: source, unfurl_id: unfurl_id, user_auth_blocks: user_auth_blocks, user_auth_message: , user_auth_required: user_auth_required, user_auth_url: user_auth_url }.to_json) end end |
#chat_update(channel:, ts:, text:, blocks:) ⇒ ApiResponse
87 88 89 |
# File 'lib/slack_bot/api_client.rb', line 87 def chat_update(channel:, ts:, text:, blocks:) perform_request { client.post("chat.update", {channel: channel, ts: ts, text: text, blocks: blocks}.to_json) } end |
#scheduled_messages_list(channel: nil, cursor: nil, latest: nil, limit: nil, oldest: nil, team_id: nil) ⇒ ApiResponse
115 116 117 118 |
# File 'lib/slack_bot/api_client.rb', line 115 def (channel: nil, cursor: nil, latest: nil, limit: nil, oldest: nil, team_id: nil) args = compact_payload(channel: channel, cursor: cursor, limit: limit, latest: latest, oldest: oldest, team_id: team_id) perform_request { client.post("scheduled_messages.list", args.to_json) } end |
#users_info(user_id:) ⇒ ApiResponse
128 129 130 |
# File 'lib/slack_bot/api_client.rb', line 128 def users_info(user_id:) perform_request { client.post("users.info", {user: user_id}.to_json) } end |
#users_list(cursor: nil, limit: 200, include_locale: nil, team_id: nil) ⇒ ApiResponse
136 137 138 139 |
# File 'lib/slack_bot/api_client.rb', line 136 def users_list(cursor: nil, limit: 200, include_locale: nil, team_id: nil) args = compact_payload(cursor: cursor, limit: limit, include_locale: include_locale, team_id: team_id) perform_request { client.post("users.list", args.to_json) } end |
#views_open(trigger_id:, view:) ⇒ ApiResponse
75 76 77 |
# File 'lib/slack_bot/api_client.rb', line 75 def views_open(trigger_id:, view:) perform_request { client.post("views.open", {trigger_id: trigger_id, view: view}.to_json) } end |
#views_publish(user_id:, view:) ⇒ ApiResponse
132 133 134 |
# File 'lib/slack_bot/api_client.rb', line 132 def views_publish(user_id:, view:) perform_request { client.post("views.publish", {user_id: user_id, view: view}.to_json) } end |
#views_update(view_id:, view:) ⇒ ApiResponse
79 80 81 |
# File 'lib/slack_bot/api_client.rb', line 79 def views_update(view_id:, view:) perform_request { client.post("views.update", {view_id: view_id, view: view}.to_json) } end |