Module: MixinBot::API::Conversation

Included in:
MixinBot::API
Defined in:
lib/mixin_bot/api/conversation.rb

Instance Method Summary collapse

Instance Method Details

#add_conversation_participants(conversation_id:, user_ids:, access_token: nil) ⇒ Object

participants = [{ user_id: “” }]



70
71
72
73
74
75
# File 'lib/mixin_bot/api/conversation.rb', line 70

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 } })

  client.post path, *payload, access_token:
end

#conversation(conversation_id, access_token: nil) ⇒ Object



6
7
8
9
# File 'lib/mixin_bot/api/conversation.rb', line 6

def conversation(conversation_id, access_token: nil)
  path = format('/conversations/%<conversation_id>s', conversation_id:)
  client.get path, access_token:
end

#conversation_by_user_id(user_id) ⇒ Object



11
12
13
14
# File 'lib/mixin_bot/api/conversation.rb', line 11

def conversation_by_user_id(user_id)
  conversation_id = unique_uuid user_id
  conversation conversation_id
end

#create_contact_conversation(user_id, access_token: nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mixin_bot/api/conversation.rb', line 38

def create_contact_conversation(user_id, access_token: nil)
  create_conversation(
    category: 'CONTACT',
    conversation_id: unique_uuid(user_id),
    participants: [
      {
        user_id:
      }
    ],
    access_token:
  )
end

#create_conversation(**kwargs) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mixin_bot/api/conversation.rb', line 16

def create_conversation(**kwargs)
  path = '/conversations'
  payload = {
    category: kwargs[:category],
    conversation_id: kwargs[:conversation_id] || SecureRandom.uuid,
    name: kwargs[:name],
    participants: kwargs[:participants]
  }.compact_blank

  client.post path, **payload, access_token: kwargs[:access_token]
end

#create_group_conversation(user_ids:, name:, conversation_id: nil, access_token: nil) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/mixin_bot/api/conversation.rb', line 28

def create_group_conversation(user_ids:, name:, conversation_id: nil, access_token: nil)
  create_conversation(
    category: 'GROUP',
    conversation_id:,
    name:,
    participants: user_ids.map(&->(participant) { { user_id: participant } }),
    access_token:
  )
end

#exit_conversation(conversation_id, access_token: nil) ⇒ Object



85
86
87
88
89
# File 'lib/mixin_bot/api/conversation.rb', line 85

def exit_conversation(conversation_id, access_token: nil)
  path = format('/conversations/%<id>s/exit', id: conversation_id)

  client.post path, access_token:
end

#remove_conversation_participants(conversation_id:, user_ids:, access_token: nil) ⇒ Object

participants = [{ user_id: “” }]



78
79
80
81
82
83
# File 'lib/mixin_bot/api/conversation.rb', line 78

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 } })

  client.post path, *payload, access_token:
end

#rotate_conversation(conversation_id, access_token: nil) ⇒ Object



91
92
93
94
95
# File 'lib/mixin_bot/api/conversation.rb', line 91

def rotate_conversation(conversation_id, access_token: nil)
  path = format('/conversations/%<id>s/rotate', id: conversation_id)

  client.post path, access_token:
end

#unique_uuid(user_id, opponent_id = nil) ⇒ Object Also known as: unique_conversation_id



105
106
107
108
# File 'lib/mixin_bot/api/conversation.rb', line 105

def unique_uuid(user_id, opponent_id = nil)
  opponent_id ||= config.app_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” }]



98
99
100
101
102
103
# File 'lib/mixin_bot/api/conversation.rb', line 98

def update_conversation_participants_role(conversation_id:, participants:, access_token: nil)
  path = format('/conversations/%<id>s/participants/ROLE', id: conversation_id)
  payload = participants

  client.post path, *payload, access_token:
end

#update_group_conversation_announcement(announcement:, conversation_id:, access_token: nil) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/mixin_bot/api/conversation.rb', line 60

def update_group_conversation_announcement(announcement:, conversation_id:, access_token: nil)
  path = format('/conversations/%<id>s', id: conversation_id)
  payload = {
    announcement:
  }

  client.post path, **payload, access_token:
end

#update_group_conversation_name(name:, conversation_id:, access_token: nil) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/mixin_bot/api/conversation.rb', line 51

def update_group_conversation_name(name:, conversation_id:, access_token: nil)
  path = format('/conversations/%<id>s', id: conversation_id)
  payload = {
    name:
  }

  client.post path, **payload, access_token:
end