Module: MixinBot::API::Conversation
- Included in:
- MixinBot::API
- Defined in:
- lib/mixin_bot/api/conversation.rb
Instance Method Summary collapse
-
#add_conversation_participants(conversation_id:, user_ids:, access_token: nil) ⇒ Object
participants = [{ user_id: “” }].
- #conversation(conversation_id) ⇒ Object (also: #read_conversation)
- #conversation_by_user_id(user_id) ⇒ Object (also: #read_conversation_by_user_id)
- #create_contact_conversation(user_id, access_token: nil) ⇒ Object
- #create_conversation(category:, conversation_id:, participants:, name: nil, access_token: nil) ⇒ Object
- #create_group_conversation(user_ids:, name:, conversation_id: nil, access_token: nil) ⇒ Object
- #exit_conversation(conversation_id, access_token: nil) ⇒ Object
-
#remove_conversation_participants(conversation_id:, user_ids:, access_token: nil) ⇒ Object
participants = [{ user_id: “” }].
- #rotate_conversation(conversation_id, access_token: nil) ⇒ Object
- #unique_uuid(user_id, opponent_id = nil) ⇒ Object (also: #unique_conversation_id)
-
#update_conversation_participants_role(conversation_id:, participants:, access_token: nil) ⇒ Object
participants = [{ user_id: “”, role: “ADMIN” }].
- #update_group_conversation_announcement(announcement:, conversation_id:, access_token: nil) ⇒ Object
- #update_group_conversation_name(name:, conversation_id:, access_token: nil) ⇒ Object
Instance Method Details
#add_conversation_participants(conversation_id:, user_ids:, access_token: nil) ⇒ Object
participants = [{ user_id: “” }]
80 81 82 83 84 85 86 87 |
# File 'lib/mixin_bot/api/conversation.rb', line 80 def add_conversation_participants(conversation_id:, user_ids:, access_token: nil) path = format('/conversations/%<id>s/participants/ADD', id: conversation_id) payload = user_ids.map(&->(participant) { { user_id: participant } }) access_token ||= access_token('POST', path, payload.to_json) = format('Bearer %<access_token>s', access_token: access_token) client.post(path, headers: { 'Authorization': }, json: payload) end |
#conversation(conversation_id) ⇒ Object Also known as: read_conversation
6 7 8 9 10 11 |
# File 'lib/mixin_bot/api/conversation.rb', line 6 def conversation(conversation_id) path = format('/conversations/%<conversation_id>s', conversation_id: conversation_id) access_token ||= access_token('GET', path, '') = format('Bearer %<access_token>s', access_token: access_token) client.get(path, headers: { 'Authorization': }) end |
#conversation_by_user_id(user_id) ⇒ Object Also known as: read_conversation_by_user_id
14 15 16 17 |
# File 'lib/mixin_bot/api/conversation.rb', line 14 def conversation_by_user_id(user_id) conversation_id = unique_conversation_id(user_id) read_conversation(conversation_id) end |
#create_contact_conversation(user_id, access_token: nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mixin_bot/api/conversation.rb', line 44 def create_contact_conversation(user_id, access_token: nil) create_conversation( category: 'CONTACT', conversation_id: unique_conversation_id(user_id), participants: [ { user_id: user_id } ], access_token: access_token ) end |
#create_conversation(category:, conversation_id:, participants:, name: nil, access_token: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mixin_bot/api/conversation.rb', line 20 def create_conversation(category:, conversation_id:, participants:, name: nil, access_token: nil) path = '/conversations' payload = { category: category, conversation_id: conversation_id || SecureRandom.uuid, name: name, participants: participants } access_token ||= access_token('POST', path, payload.to_json) = format('Bearer %<access_token>s', access_token: access_token) client.post(path, headers: { 'Authorization': }, json: payload) end |
#create_group_conversation(user_ids:, name:, conversation_id: nil, access_token: nil) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/mixin_bot/api/conversation.rb', line 34 def create_group_conversation(user_ids:, name:, conversation_id: nil, access_token: nil) create_conversation( category: 'GROUP', conversation_id: conversation_id, name: name, participants: user_ids.map(&->(participant) { { user_id: participant } }), access_token: access_token ) end |
#exit_conversation(conversation_id, access_token: nil) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/mixin_bot/api/conversation.rb', line 99 def exit_conversation(conversation_id, access_token: nil) path = format('/conversations/%<id>s/exit', id: conversation_id) access_token ||= access_token('POST', path) = format('Bearer %<access_token>s', access_token: access_token) client.post(path, headers: { 'Authorization': }) end |
#remove_conversation_participants(conversation_id:, user_ids:, access_token: nil) ⇒ Object
participants = [{ user_id: “” }]
90 91 92 93 94 95 96 97 |
# File 'lib/mixin_bot/api/conversation.rb', line 90 def remove_conversation_participants(conversation_id:, user_ids:, access_token: nil) path = format('/conversations/%<id>s/participants/REMOVE', id: conversation_id) payload = user_ids.map(&->(participant) { { user_id: participant } }) access_token ||= access_token('POST', path, payload.to_json) = format('Bearer %<access_token>s', access_token: access_token) client.post(path, headers: { 'Authorization': }, json: payload) end |
#rotate_conversation(conversation_id, access_token: nil) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/mixin_bot/api/conversation.rb', line 107 def rotate_conversation(conversation_id, access_token: nil) path = format('/conversations/%<id>s/rotate', id: conversation_id) access_token ||= access_token('POST', path) = format('Bearer %<access_token>s', access_token: access_token) client.post(path, headers: { 'Authorization': }) end |
#unique_uuid(user_id, opponent_id = nil) ⇒ Object Also known as: unique_conversation_id
125 126 127 128 |
# File 'lib/mixin_bot/api/conversation.rb', line 125 def unique_uuid(user_id, opponent_id = nil) opponent_id ||= client_id MixinBot::Utils.unique_uuid user_id, opponent_id end |
#update_conversation_participants_role(conversation_id:, participants:, access_token: nil) ⇒ Object
participants = [{ user_id: “”, role: “ADMIN” }]
116 117 118 119 120 121 122 123 |
# File 'lib/mixin_bot/api/conversation.rb', line 116 def update_conversation_participants_role(conversation_id:, participants:, access_token: nil) path = format('/conversations/%<id>s/participants/ROLE', id: conversation_id) payload = participants access_token ||= access_token('POST', path, payload.to_json) = format('Bearer %<access_token>s', access_token: access_token) client.post(path, headers: { 'Authorization': }, json: payload) end |
#update_group_conversation_announcement(announcement:, conversation_id:, access_token: nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/mixin_bot/api/conversation.rb', line 68 def update_group_conversation_announcement(announcement:, conversation_id:, access_token: nil) path = format('/conversations/%<id>s', id: conversation_id) payload = { announcement: announcement } access_token ||= access_token('POST', path, payload.to_json) = format('Bearer %<access_token>s', access_token: access_token) client.post(path, headers: { 'Authorization': }, json: payload) end |
#update_group_conversation_name(name:, conversation_id:, access_token: nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mixin_bot/api/conversation.rb', line 57 def update_group_conversation_name(name:, conversation_id:, access_token: nil) path = format('/conversations/%<id>s', id: conversation_id) payload = { name: name } access_token ||= access_token('POST', path, payload.to_json) = format('Bearer %<access_token>s', access_token: access_token) client.post(path, headers: { 'Authorization': }, json: payload) end |