Module: Keybase::Local::Chat
- Defined in:
- lib/keybase/local/chat.rb
Overview
Represents Keybase's JSON chat API.
Constant Summary collapse
- CHAT_EXEC_ARGS =
The initial arguments to pass when executing Keybase for chatting.
%w[keybase chat api].freeze
Class Method Summary collapse
-
.chat_call(meth, options: {}) ⇒ OpenStruct
private
Makes chat API calls.
-
.conversation(users, peek: false, unread_only: false) ⇒ OpenStruct
Read a conversation.
-
.delete_message(users, id) ⇒ OpenStruct
Delete a message from a conversation.
-
.download_attachment(users, id, path) ⇒ OpenStruct
Download a file from a conversation.
-
.edit_message(users, id, message) ⇒ OpenStruct
Edit a message in a conversation.
-
.envelope(meth, options: {}) ⇒ String
private
The JSON serialized envelope.
-
.list_inbox(topic_type: nil) ⇒ OpenStruct
List the current user's inbox.
-
.mark_conversation(users, id) ⇒ OpenStruct
Make a conversation as read up to a specific ID.
-
.mute_conversation(users) ⇒ OpenStruct
Mute a conversation.
-
.send_message(users, message, public: false, exploding_lifetime: nil) ⇒ OpenStruct
Send a message to a conversation.
-
.send_team_message(team, topic, message, exploding_lifetime: nil) ⇒ OpenStruct
Send a message to a team-based conversation.
-
.unwrap(struct) ⇒ OpenStruct
private
Cleans up the object returned by Chat.chat_call.
-
.upload_attachment(users, path, title) ⇒ OpenStruct
Upload a file to a conversation.
Class Method Details
.chat_call(meth, options: {}) ⇒ OpenStruct
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Makes chat API calls.
45 46 47 48 49 50 51 52 53 |
# File 'lib/keybase/local/chat.rb', line 45 def chat_call(meth, options: {}) response = Open3.popen3(*CHAT_EXEC_ARGS) do |stdin, stdout, _, _| stdin.write envelope meth, options: stdin.close stdout.read end unwrap JSON.parse response, object_class: OpenStruct end |
.conversation(users, peek: false, unread_only: false) ⇒ OpenStruct
Read a conversation.
71 72 73 74 75 76 77 78 79 |
# File 'lib/keybase/local/chat.rb', line 71 def conversation(users, peek: false, unread_only: false) chat_call :read, options: { channel: { name: Core::U[*users], }, peek: peek, unread_only: unread_only, } end |
.delete_message(users, id) ⇒ OpenStruct
Delete a message from a conversation.
130 131 132 133 134 135 136 137 |
# File 'lib/keybase/local/chat.rb', line 130 def (users, id) chat_call :delete, options: { channel: { name: Core::U[*users], }, message_id: id, } end |
.download_attachment(users, id, path) ⇒ OpenStruct
Download a file from a conversation.
179 180 181 182 183 184 185 186 187 |
# File 'lib/keybase/local/chat.rb', line 179 def (users, id, path) chat_call :download, options: { channel: { name: Core::U[*users], }, message_id: id, output: path, } end |
.edit_message(users, id, message) ⇒ OpenStruct
Edit a message in a conversation.
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/keybase/local/chat.rb', line 145 def (users, id, ) chat_call :edit, options: { channel: { name: Core::U[*users], }, message_id: id, message: { body: , }, } end |
.envelope(meth, options: {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the JSON serialized envelope.
19 20 21 22 23 24 25 26 |
# File 'lib/keybase/local/chat.rb', line 19 def envelope(meth, options: {}) { method: meth, params: { options: , }, }.to_json end |
.list_inbox(topic_type: nil) ⇒ OpenStruct
List the current user's inbox.
59 60 61 62 63 |
# File 'lib/keybase/local/chat.rb', line 59 def list_inbox(topic_type: nil) chat_call :list, options: { topic_type: topic_type, } end |
.mark_conversation(users, id) ⇒ OpenStruct
Make a conversation as read up to a specific ID.
194 195 196 197 198 199 200 201 |
# File 'lib/keybase/local/chat.rb', line 194 def mark_conversation(users, id) chat_call :mark, options: { channel: { name: Core::U[*users], }, message_id: id, } end |
.mute_conversation(users) ⇒ OpenStruct
Mute a conversation.
207 208 209 210 211 212 213 214 |
# File 'lib/keybase/local/chat.rb', line 207 def mute_conversation(users) chat_call :setstatus, options: { channel: { name: Core::U[*users], }, status: "muted", } end |
.send_message(users, message, public: false, exploding_lifetime: nil) ⇒ OpenStruct
Send a message to a conversation. For team-based conversations, see send_team_message.
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/keybase/local/chat.rb', line 89 def (users, , public: false, exploding_lifetime: nil) chat_call :send, options: { channel: { name: Core::U[*users], public: public, }, exploding_lifetime: exploding_lifetime, message: { body: , }, } end |
.send_team_message(team, topic, message, exploding_lifetime: nil) ⇒ OpenStruct
Send a message to a team-based conversation. For conversations between individual users, see send_message.
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/keybase/local/chat.rb', line 111 def (team, topic, , exploding_lifetime: nil) chat_call :send, options: { channel: { name: team, members_type: "team", topic_name: topic, }, exploding_lifetime: exploding_lifetime, message: { body: , }, } end |
.unwrap(struct) ⇒ OpenStruct
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Cleans up the object returned by chat_call.
33 34 35 36 37 |
# File 'lib/keybase/local/chat.rb', line 33 def unwrap(struct) raise Exceptions::ChatError, struct.error. if struct.error struct.result end |
.upload_attachment(users, path, title) ⇒ OpenStruct
Upload a file to a conversation.
163 164 165 166 167 168 169 170 171 |
# File 'lib/keybase/local/chat.rb', line 163 def (users, path, title) chat_call :attach, options: { channel: { name: Core::U[*users], }, filename: path, title: title, } end |