Module: Legion::Extensions::MicrosoftTeams::Runners::Chats
- Extended by:
- Definitions
- Includes:
- Helpers::Lex, Helpers::Client
- Included in:
- Client
- Defined in:
- lib/legion/extensions/microsoft_teams/runners/chats.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#bot_connection, #graph_connection, #oauth_connection, #user_path
Class Method Details
.trigger_words ⇒ Object
13
14
15
|
# File 'lib/legion/extensions/microsoft_teams/runners/chats.rb', line 13
def self.trigger_words
%w[chat chats conversation conversations dm direct]
end
|
Instance Method Details
#add_chat_member(chat_id:, user_id:, roles: ['owner']) ⇒ Object
131
132
133
134
135
136
137
138
139
|
# File 'lib/legion/extensions/microsoft_teams/runners/chats.rb', line 131
def add_chat_member(chat_id:, user_id:, roles: ['owner'], **)
payload = {
'@odata.type' => '#microsoft.graph.aadUserConversationMember',
'roles' => roles,
'user@odata.bind' => "https://graph.microsoft.com/v1.0/users('#{user_id}')"
}
response = graph_connection(**).post("chats/#{chat_id}/members", payload)
{ result: response.body }
end
|
#create_chat(members:, chat_type: 'oneOnOne', topic: nil) ⇒ Object
98
99
100
101
102
103
|
# File 'lib/legion/extensions/microsoft_teams/runners/chats.rb', line 98
def create_chat(members:, chat_type: 'oneOnOne', topic: nil, **)
payload = { chatType: chat_type, members: members }
payload[:topic] = topic if topic
response = graph_connection(**).post('chats', payload)
{ result: response.body }
end
|
#get_chat(chat_id:) ⇒ Object
79
80
81
82
83
|
# File 'lib/legion/extensions/microsoft_teams/runners/chats.rb', line 79
def get_chat(chat_id:, **)
log.debug("get_chat(chat_id: #{chat_id}, **)")
response = graph_connection(**).get("chats/#{chat_id}")
{ result: response.body }
end
|
#list_chat_members(chat_id:) ⇒ Object
114
115
116
117
118
|
# File 'lib/legion/extensions/microsoft_teams/runners/chats.rb', line 114
def list_chat_members(chat_id:, **)
log.debug "list_chat_members(chat_id: #{chat_id})"
response = graph_connection(**).get("chats/#{chat_id}/members")
{ result: response.body }
end
|
#list_chats(user_id: 'me', top: 50, max_pages: 1, expand: nil, filter: nil, orderby: nil) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/legion/extensions/microsoft_teams/runners/chats.rb', line 36
def list_chats(user_id: 'me', top: 50, max_pages: 1, expand: nil, filter: nil, orderby: nil, **)
log.debug "list_chats(user_id: #{user_id}, top: #{top}, max_pages: #{max_pages})"
per_page = [top, 50].min
params = { '$top' => per_page }
params['$expand'] = expand if expand
params['$filter'] = filter if filter
params['$orderby'] = orderby if orderby
conn = graph_connection(**)
response = conn.get("#{user_path(user_id)}/chats", params)
body = response.body
return { result: body } if max_pages <= 1
all_values = Array(body['value'] || body[:value])
next_link = body['@odata.nextLink'] || body[:'@odata.nextLink']
pages_fetched = 1
while next_link && pages_fetched < max_pages
response = conn.get(next_link)
page_body = response.body
items = page_body['value'] || page_body[:value]
all_values.concat(Array(items)) if items
next_link = page_body['@odata.nextLink'] || page_body[:'@odata.nextLink']
pages_fetched += 1
end
result = { '@odata.context' => body['@odata.context'] || body[:'@odata.context'],
'value' => all_values }
result['@odata.nextLink'] = next_link if next_link
{ result: result }
end
|