Module: Legion::Extensions::MicrosoftTeams::Runners::Subscriptions
- Includes:
- Helpers::Lex, Helpers::Client
- Included in:
- Client
- Defined in:
- lib/legion/extensions/microsoft_teams/runners/subscriptions.rb
Class Method Summary
collapse
Instance Method Summary
collapse
-
#create_subscription(resource:, change_type:, notification_url:, expiration:, client_state: nil, include_resource_data: false) ⇒ Object
-
#delete_subscription(subscription_id:) ⇒ Object
-
#get_subscription(subscription_id:) ⇒ Object
-
#list_subscriptions ⇒ Object
-
#renew_subscription(subscription_id:, expiration:) ⇒ Object
-
#subscribe_to_channel_messages(team_id:, channel_id:, notification_url:, expiration:, client_state: nil) ⇒ Object
-
#subscribe_to_chat_messages(chat_id:, notification_url:, expiration:, client_state: nil) ⇒ Object
#bot_connection, #graph_connection, #oauth_connection, #user_path
Class Method Details
.trigger_words ⇒ Object
12
13
14
|
# File 'lib/legion/extensions/microsoft_teams/runners/subscriptions.rb', line 12
def self.trigger_words
%w[subscription subscriptions webhook webhooks subscribe watch]
end
|
Instance Method Details
#create_subscription(resource:, change_type:, notification_url:, expiration:, client_state: nil, include_resource_data: false) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/legion/extensions/microsoft_teams/runners/subscriptions.rb', line 61
def create_subscription(resource:, change_type:, notification_url:, expiration:,
client_state: nil, include_resource_data: false, **)
payload = {
changeType: change_type,
notificationUrl: notification_url,
resource: resource,
expirationDateTime: expiration,
includeResourceData: include_resource_data
}
payload[:clientState] = client_state if client_state
response = graph_connection(**).post('subscriptions', payload)
{ result: response.body }
end
|
#delete_subscription(subscription_id:) ⇒ Object
103
104
105
106
|
# File 'lib/legion/extensions/microsoft_teams/runners/subscriptions.rb', line 103
def delete_subscription(subscription_id:, **)
response = graph_connection(**).delete("subscriptions/#{subscription_id}")
{ result: response.body }
end
|
#get_subscription(subscription_id:) ⇒ Object
39
40
41
42
|
# File 'lib/legion/extensions/microsoft_teams/runners/subscriptions.rb', line 39
def get_subscription(subscription_id:, **)
response = graph_connection(**).get("subscriptions/#{subscription_id}")
{ result: response.body }
end
|
#list_subscriptions ⇒ Object
24
25
26
27
|
# File 'lib/legion/extensions/microsoft_teams/runners/subscriptions.rb', line 24
def list_subscriptions(**)
response = graph_connection(**).get('subscriptions')
{ result: response.body }
end
|
#renew_subscription(subscription_id:, expiration:) ⇒ Object
87
88
89
90
91
|
# File 'lib/legion/extensions/microsoft_teams/runners/subscriptions.rb', line 87
def renew_subscription(subscription_id:, expiration:, **)
payload = { expirationDateTime: expiration }
response = graph_connection(**).patch("subscriptions/#{subscription_id}", payload)
{ result: response.body }
end
|
#subscribe_to_channel_messages(team_id:, channel_id:, notification_url:, expiration:, client_state: nil) ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/legion/extensions/microsoft_teams/runners/subscriptions.rb', line 144
def subscribe_to_channel_messages(team_id:, channel_id:, notification_url:, expiration:,
client_state: nil, **)
create_subscription(
resource: "/teams/#{team_id}/channels/#{channel_id}/messages",
change_type: 'created,updated',
notification_url: notification_url,
expiration: expiration,
client_state: client_state,
**
)
end
|
#subscribe_to_chat_messages(chat_id:, notification_url:, expiration:, client_state: nil) ⇒ Object
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/legion/extensions/microsoft_teams/runners/subscriptions.rb', line 120
def subscribe_to_chat_messages(chat_id:, notification_url:, expiration:, client_state: nil, **)
create_subscription(
resource: "/chats/#{chat_id}/messages",
change_type: 'created,updated',
notification_url: notification_url,
expiration: expiration,
client_state: client_state,
**
)
end
|