Class: SlackBot::ApiClient
- Inherits:
-
Object
- Object
- SlackBot::ApiClient
- Defined in:
- lib/slack_bot/api_client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #chat_delete(channel:, ts:) ⇒ Object
- #chat_delete_scheduled_message(channel:, scheduled_message_id:) ⇒ Object
- #chat_get_permalink(channel:, message_ts:) ⇒ Object
- #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) ⇒ Object
- #chat_post_message(channel:, text:, blocks:) ⇒ Object
- #chat_schedule_message(channel:, text:, post_at:, blocks: nil) ⇒ Object
- #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) ⇒ Object
- #chat_update(channel:, ts:, text:, blocks:) ⇒ Object
-
#initialize(authorization_token: ENV["SLACK_BOT_API_TOKEN"]) ⇒ ApiClient
constructor
A new instance of ApiClient.
- #scheduled_messages_list(channel: nil, cursor: nil, latest: nil, limit: nil, oldest: nil, team_id: nil) ⇒ Object
- #users_info(user_id:) ⇒ Object
- #users_list(cursor: nil, limit: 200, include_locale: nil, team_id: nil) ⇒ Object
- #views_open(trigger_id:, view:) ⇒ Object
- #views_publish(user_id:, view:) ⇒ Object
- #views_update(view_id:, view:) ⇒ Object
Constructor Details
#initialize(authorization_token: ENV["SLACK_BOT_API_TOKEN"]) ⇒ ApiClient
Returns a new instance of ApiClient.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/slack_bot/api_client.rb', line 26 def initialize(authorization_token: ENV["SLACK_BOT_API_TOKEN"]) = !.nil? && .is_a?(String) && !.empty? raise "Slack bot API token is not set" if ! @client = Faraday.new do |conn| conn.request :url_encoded conn.adapter Faraday.default_adapter conn.url_prefix = "https://slack.com/api/" conn.headers["Content-Type"] = "application/json; charset=utf-8" conn.headers["Authorization"] = "Bearer #{}" end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
25 26 27 |
# File 'lib/slack_bot/api_client.rb', line 25 def client @client end |
Instance Method Details
#chat_delete(channel:, ts:) ⇒ Object
56 57 58 |
# File 'lib/slack_bot/api_client.rb', line 56 def chat_delete(channel:, ts:) ApiResponse.new { client.post("chat.delete", {channel: channel, ts: ts}.to_json) } end |
#chat_delete_scheduled_message(channel:, scheduled_message_id:) ⇒ Object
89 90 91 |
# File 'lib/slack_bot/api_client.rb', line 89 def (channel:, scheduled_message_id:) ApiResponse.new { client.post("chat.deleteScheduledMessage", {channel: channel, scheduled_message_id: }.to_json) } end |
#chat_get_permalink(channel:, message_ts:) ⇒ Object
93 94 95 |
# File 'lib/slack_bot/api_client.rb', line 93 def chat_get_permalink(channel:, message_ts:) ApiResponse.new { 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) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/slack_bot/api_client.rb', line 114 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 = {} args[:channel] = channel args[:user] = user args[:text] = text if text args[:as_user] = as_user if as_user args[:attachments] = if args[:blocks] = blocks if blocks args[:icon_emoji] = icon_emoji if icon_emoji args[:icon_url] = icon_url if icon_url args[:link_names] = link_names if link_names args[:parse] = parse if parse args[:thread_ts] = thread_ts if thread_ts args[:username] = username if username ApiResponse.new { client.post("chat.postEphemeral", args.to_json) } end |
#chat_post_message(channel:, text:, blocks:) ⇒ Object
48 49 50 |
# File 'lib/slack_bot/api_client.rb', line 48 def (channel:, text:, blocks:) ApiResponse.new { client.post("chat.postMessage", {channel: channel, text: text, blocks: blocks}.to_json) } end |
#chat_schedule_message(channel:, text:, post_at:, blocks: nil) ⇒ Object
74 75 76 |
# File 'lib/slack_bot/api_client.rb', line 74 def (channel:, text:, post_at:, blocks: nil) ApiResponse.new { 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) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/slack_bot/api_client.rb', line 60 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) ApiResponse.new { 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 |
#chat_update(channel:, ts:, text:, blocks:) ⇒ Object
52 53 54 |
# File 'lib/slack_bot/api_client.rb', line 52 def chat_update(channel:, ts:, text:, blocks:) ApiResponse.new { 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) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/slack_bot/api_client.rb', line 78 def (channel: nil, cursor: nil, latest: nil, limit: nil, oldest: nil, team_id: nil) ApiResponse.new { client.post("scheduled_messages.list", { channel: channel, cursor: cursor, latest: latest, limit: limit, oldest: oldest, team_id: team_id }.to_json) } end |
#users_info(user_id:) ⇒ Object
97 98 99 |
# File 'lib/slack_bot/api_client.rb', line 97 def users_info(user_id:) ApiResponse.new { client.post("users.info", {user: user_id}.to_json) } end |
#users_list(cursor: nil, limit: 200, include_locale: nil, team_id: nil) ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/slack_bot/api_client.rb', line 105 def users_list(cursor: nil, limit: 200, include_locale: nil, team_id: nil) args = {} args[:cursor] = cursor if cursor args[:limit] = limit if limit args[:include_locale] = include_locale if include_locale args[:team_id] = team_id if team_id ApiResponse.new { client.post("users.list", args.to_json) } end |
#views_open(trigger_id:, view:) ⇒ Object
40 41 42 |
# File 'lib/slack_bot/api_client.rb', line 40 def views_open(trigger_id:, view:) ApiResponse.new { client.post("views.open", {trigger_id: trigger_id, view: view}.to_json) } end |
#views_publish(user_id:, view:) ⇒ Object
101 102 103 |
# File 'lib/slack_bot/api_client.rb', line 101 def views_publish(user_id:, view:) ApiResponse.new { client.post("views.publish", {user_id: user_id, view: view}.to_json) } end |
#views_update(view_id:, view:) ⇒ Object
44 45 46 |
# File 'lib/slack_bot/api_client.rb', line 44 def views_update(view_id:, view:) ApiResponse.new { client.post("views.update", {view_id: view_id, view: view}.to_json) } end |