microsoft_teams_incoming_webhook_ruby 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/publish_to_rubygems.yml +0 -1
- data/.gitignore +3 -1
- data/README.md +300 -58
- data/lib/microsoft_teams_incoming_webhook_ruby/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39b4271906654ad2de7ff8ec2498b3aff1fd06254d2907cf2c7057ce56953b2c
|
4
|
+
data.tar.gz: f0aafd0aa31ef6f89e9d757754006bd02a96eab0771cfe79469df497b8fb4558
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9378f2e20942e2b655e11f3d7f0fb185f20f21086e2ddb4a593824bdd308dbfb4286107965f1b10fc9e6507ab81bfd632be8d9d2a0541e141610f0798b377d6e
|
7
|
+
data.tar.gz: 6560b0e12bcd0787255fc63351cecc2e71700caa4d30665426f1b853415c7a05a7736e8b56fb96d47c4667311084c289c596b141c622ce38e7bfeacd87451be4
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -41,12 +41,17 @@ The first step before using this gem is to configure the connector inside your T
|
|
41
41
|
|
42
42
|
For this purpose, please check the official documentation from Microsoft. It's listed below some useful links:
|
43
43
|
|
44
|
-
- https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook
|
44
|
+
- https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook
|
45
|
+
- https://techcommunity.microsoft.com/t5/microsoft-365-pnp-blog/how-to-configure-and-use-incoming-webhooks-in-microsoft-teams/ba-p/2051118
|
45
46
|
- https://www.youtube.com/watch?v=amvh4rzTCS0
|
46
47
|
|
47
|
-
|
48
|
+
After the configuration, keep your generated Incoming Webhook URL in a secret and secure way.
|
48
49
|
|
49
|
-
|
50
|
+
You will use it (the URL) in next sections of README.
|
51
|
+
|
52
|
+
### Hello World message sending
|
53
|
+
|
54
|
+
Once you have configured Incoming Webhook inside your Teams channels, you can send a very simple `Hello World` message:
|
50
55
|
|
51
56
|
```ruby
|
52
57
|
require 'microsoft_teams_incoming_webhook_ruby'
|
@@ -59,83 +64,324 @@ end
|
|
59
64
|
message.send
|
60
65
|
```
|
61
66
|
|
62
|
-
Note that there are 2 keys that is the minimum required to define a valid message:
|
67
|
+
Note that there are 2 keys that is the minimum required to define a valid message for Teams:
|
63
68
|
- `url`: The URL of Incoming Webhook connector, generated via Microsoft Teams
|
64
69
|
- `text`: The text of your message
|
65
70
|
|
66
|
-
There are many other possible keys to be sent to Microsoft Incoming Webhook API.
|
71
|
+
There are many other possible keys to be sent to Microsoft Incoming Webhook API.
|
72
|
+
But pay attention to always send **at least** the 2 keys.
|
73
|
+
|
74
|
+
### Gem public interface
|
75
|
+
|
76
|
+
The `MicrosoftTeamsIncomingWebhookRuby::Message` class has 3 main methods:
|
77
|
+
|
78
|
+
- `new`: Initialization of object. You need to pass a block as parameter, containing the message structure. This structure will be converted automatically to JSON and be sent to Microsoft Incoming Webhook API.
|
79
|
+
- `builder`: Message builder object, that allows add/redefine/remove fields arbitrarily.
|
80
|
+
- `send`: Invocation of Incoming Webhook API, using HTTPS.
|
81
|
+
|
82
|
+
### Message structure
|
83
|
+
|
84
|
+
The Microsoft Incoming Webhook API allows us to send a variety of fields, that will result in diferents cards displayed in Teams channels.
|
85
|
+
|
86
|
+
Because of this, the gem will not enforce any schema in message structure. The only required parameters are `url` and `text`. Any other options will be accepted, considering that Microsoft Incoming Webhook API accepts it.
|
67
87
|
|
68
88
|
### Configuration of message structure lately of initialization
|
69
89
|
|
70
|
-
|
90
|
+
The message structure and its fields can be defined in two moments:
|
91
|
+
|
92
|
+
- Initialization of `MicrosoftTeamsIncomingWebhookRuby::Message` object
|
93
|
+
- After object initialization, but before `send` method call
|
94
|
+
|
95
|
+
🚨 You can add/replace/remove any fields arbitrarily, but keeping at least the minimum required fields (`url` and `text`). Otherwise, an error will be generated when invoke `send` method.
|
96
|
+
|
97
|
+
Below there are some examples of this manipulation:
|
98
|
+
|
99
|
+
- Initialization of attributes in `MicrosoftTeamsIncomingWebhookRuby::Message` object
|
71
100
|
|
72
|
-
You can build the message with any supported [card fields](https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#card-fields).
|
73
|
-
This example is taken directly from [Microsoft Docs](https://docs.microsoft.com/en-us/outlook/actionable-messages/send-via-connectors)
|
74
101
|
```ruby
|
75
|
-
require
|
102
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
76
103
|
|
77
|
-
message =
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
{
|
84
|
-
"@type": "ActionCard",
|
85
|
-
"name": "Send Feedback",
|
86
|
-
"inputs": [{
|
87
|
-
"@type": "TextInput",
|
88
|
-
"id": "feedback",
|
89
|
-
"isMultiline": true,
|
90
|
-
"title": "Let us know what you think about Actionable Messages"
|
91
|
-
}],
|
92
|
-
"actions": [{
|
93
|
-
"@type": "HttpPOST",
|
94
|
-
"name": "Send Feedback",
|
95
|
-
"isPrimary": true,
|
96
|
-
"target": "http://..."
|
97
|
-
}]
|
98
|
-
},
|
99
|
-
{
|
100
|
-
"@type": "OpenUri",
|
101
|
-
"name": "Learn More",
|
102
|
-
"targets": [
|
103
|
-
{ "os": "default", "uri": "https://docs.microsoft.com/outlook/actionable-messages" }
|
104
|
-
]
|
105
|
-
}
|
106
|
-
]
|
104
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
105
|
+
m.url = 'YOUR INCOMING WEBHOOK URL HERE'
|
106
|
+
m.text = 'Hello World!'
|
107
|
+
|
108
|
+
m.my_arbitrary_field = 'My value'
|
109
|
+
m.my_another_arbitrary_field = { my: 'value' }
|
107
110
|
end
|
108
111
|
|
109
|
-
|
110
|
-
|
112
|
+
message.send
|
113
|
+
```
|
114
|
+
|
115
|
+
- Adding of attribute after object initialization, but before `send` method call
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
119
|
+
|
120
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
121
|
+
m.url = 'YOUR INCOMING WEBHOOK URL HERE'
|
122
|
+
m.text = 'Hello World!'
|
123
|
+
end
|
124
|
+
|
125
|
+
message.builder.my_arbitrary_field = 'My value'
|
126
|
+
message.builder.my_another_arbitrary_field = { my: 'value' }
|
111
127
|
|
112
128
|
message.send
|
113
129
|
```
|
114
130
|
|
115
|
-
|
131
|
+
- Removing of attributes after object initialization, but before `send` method call
|
116
132
|
|
117
|
-
|
133
|
+
```ruby
|
134
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
135
|
+
|
136
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
137
|
+
m.url = 'YOUR INCOMING WEBHOOK URL HERE'
|
138
|
+
m.text = 'Hello World!'
|
139
|
+
|
140
|
+
m.my_custom_field = 'My custom value'
|
141
|
+
end
|
142
|
+
|
143
|
+
message.builder.delete_field :my_custom_field
|
144
|
+
|
145
|
+
message.send
|
146
|
+
```
|
147
|
+
|
148
|
+
- Redefing of attributes after object initialization, but before `send` method call
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
152
|
+
|
153
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
154
|
+
m.url = 'YOUR INCOMING WEBHOOK URL HERE'
|
155
|
+
m.text = 'Hello World!'
|
156
|
+
|
157
|
+
m.my_custom_field = 'My custom value'
|
158
|
+
end
|
159
|
+
|
160
|
+
message.builder.my_custom_field = 'Updated value'
|
161
|
+
|
162
|
+
message.send
|
163
|
+
```
|
164
|
+
|
165
|
+
In case of keys that starts with **@**, is necessary to use brackets notation:
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
169
|
+
|
170
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
171
|
+
m.url = 'YOUR INCOMING WEBHOOK URL HERE'
|
172
|
+
m.text = 'Hello World!'
|
173
|
+
m['@my_field'] = 'Lorem ipsum'
|
174
|
+
end
|
175
|
+
|
176
|
+
message.builder['@my_another_new_field'] = 'Ipsum valorium'
|
177
|
+
|
178
|
+
message.send
|
179
|
+
```
|
180
|
+
|
181
|
+
### Error handling
|
182
|
+
|
183
|
+
If the builder object turn itself invalid before invocation of `send` method, the gem will raise a `MicrosoftTeamsIncomingWebhookRuby::Message::Error::InvalidMessage` exception:
|
118
184
|
|
119
185
|
```ruby
|
120
|
-
|
186
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
187
|
+
|
188
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
189
|
+
m.url = 'YOUR INCOMING WEBHOOK URL HERE'
|
190
|
+
m.text = 'Hello World!'
|
191
|
+
end
|
192
|
+
|
193
|
+
message.delete_field :url
|
194
|
+
|
121
195
|
begin
|
122
|
-
|
123
|
-
rescue
|
124
|
-
|
196
|
+
message.send
|
197
|
+
rescue MicrosoftTeamsIncomingWebhookRuby::Message::Error::InvalidMessage
|
198
|
+
puts 'Your message structure is invalid!'
|
125
199
|
end
|
126
200
|
```
|
127
201
|
|
202
|
+
```ruby
|
203
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
204
|
+
|
205
|
+
begin
|
206
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
207
|
+
m.my_only_one_field = 'Lorem ipsum'
|
208
|
+
end
|
209
|
+
rescue MicrosoftTeamsIncomingWebhookRuby::Message::Error::InvalidMessage
|
210
|
+
puts 'Your message structure is invalid'
|
211
|
+
end
|
212
|
+
```
|
128
213
|
|
129
|
-
|
214
|
+
If a non-successful response code be returned by API (1xx, 4xx or 5xx), the gem will raise a `MicrosoftTeamsIncomingWebhookRuby::Message::Error::FailedRequest` exception:
|
130
215
|
|
131
216
|
```ruby
|
132
|
-
|
133
|
-
|
134
|
-
|
217
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
218
|
+
|
219
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
220
|
+
m.url = 'YOUR INCOMING WEBHOOK URL HERE'
|
221
|
+
m.text = 'My message'
|
222
|
+
end
|
223
|
+
|
224
|
+
begin
|
225
|
+
message.send
|
226
|
+
rescue MicrosoftTeamsIncomingWebhookRuby::Message::Error::FailedRequest
|
227
|
+
puts 'Microsoft API is down, broken, or your network failed!'
|
228
|
+
end
|
229
|
+
```
|
230
|
+
|
231
|
+
## Examples
|
232
|
+
|
233
|
+
You can build and send messages with any supported card fields provided by Microsoft:
|
234
|
+
|
235
|
+
- https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using
|
236
|
+
- https://adaptivecards.io/samples
|
237
|
+
- https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference
|
238
|
+
- https://amdesigner.azurewebsites.net
|
239
|
+
- https://messagecardplayground.azurewebsites.net
|
240
|
+
- https://docs.microsoft.com/en-us/outlook/actionable-messages/adaptive-card
|
241
|
+
- https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/what-are-webhooks-and-connectors
|
242
|
+
|
243
|
+
We will provide below some ready-to-go examples to be used, based on API described in links above.
|
244
|
+
|
245
|
+
### Minimal
|
246
|
+
|
247
|
+
```ruby
|
248
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
249
|
+
|
250
|
+
webhook_url = 'YOUR INCOMING WEBHOOK URL HERE'
|
251
|
+
|
252
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
253
|
+
m.url = webhook_url
|
254
|
+
m.text = 'Minimal message!'
|
255
|
+
end
|
256
|
+
|
257
|
+
message.send
|
258
|
+
```
|
259
|
+
|
260
|
+
### Theme color
|
261
|
+
|
262
|
+
```ruby
|
263
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
264
|
+
|
265
|
+
webhook_url = 'YOUR INCOMING WEBHOOK URL HERE'
|
266
|
+
|
267
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
268
|
+
m.url = webhook_url
|
269
|
+
m.text = 'Message with theme color!'
|
270
|
+
m.themeColor = 'FF0000'
|
271
|
+
end
|
272
|
+
|
273
|
+
message.send
|
274
|
+
```
|
275
|
+
|
276
|
+
### Title
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
280
|
+
|
281
|
+
webhook_url = 'YOUR INCOMING WEBHOOK URL HERE'
|
282
|
+
|
283
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
284
|
+
m.url = webhook_url
|
285
|
+
m.text = 'Message with title!'
|
286
|
+
m.title = 'FF0000'
|
287
|
+
end
|
288
|
+
|
289
|
+
message.send
|
290
|
+
```
|
291
|
+
|
292
|
+
### Summary
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
296
|
+
|
297
|
+
webhook_url = 'YOUR INCOMING WEBHOOK URL HERE'
|
298
|
+
|
299
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
300
|
+
m.url = webhook_url
|
301
|
+
m.text = 'Message with summary!'
|
302
|
+
m.summary = 'My summary'
|
303
|
+
end
|
304
|
+
|
305
|
+
message.send
|
306
|
+
```
|
307
|
+
|
308
|
+
### Potential action
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
312
|
+
|
313
|
+
webhook_url = 'YOUR INCOMING WEBHOOK URL HERE'
|
314
|
+
|
315
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
316
|
+
m.url = webhook_url
|
317
|
+
m.text = 'Message with potential action!'
|
318
|
+
m.potentialAction = [
|
319
|
+
{
|
320
|
+
'@type': 'ActionCard',
|
321
|
+
'name': 'Answer',
|
322
|
+
'inputs': [
|
323
|
+
{
|
324
|
+
'@type': 'TextInput',
|
325
|
+
'id': 'title',
|
326
|
+
'isMultiline': true,
|
327
|
+
'title': 'Your text here'
|
328
|
+
}
|
329
|
+
],
|
330
|
+
'actions': [
|
331
|
+
{
|
332
|
+
'@type': 'HttpPOST',
|
333
|
+
'name': 'Send my answer',
|
334
|
+
'isPrimary': true,
|
335
|
+
'target': 'https://example.com/example'
|
336
|
+
}
|
337
|
+
]
|
338
|
+
},
|
339
|
+
{
|
340
|
+
'@type': 'HttpPOST',
|
341
|
+
'name': 'Make another action',
|
342
|
+
'target': 'https://example.com/example2'
|
343
|
+
},
|
344
|
+
{
|
345
|
+
'@type': 'OpenUri',
|
346
|
+
'name': 'Open a URL',
|
347
|
+
'targets': [
|
348
|
+
{
|
349
|
+
'os': 'default',
|
350
|
+
'uri': 'https://github.com/pedrofurtado/microsoft_teams_incoming_webhook_ruby'
|
351
|
+
}
|
352
|
+
]
|
353
|
+
}
|
354
|
+
]
|
135
355
|
end
|
136
356
|
|
137
|
-
|
357
|
+
message.send
|
358
|
+
```
|
359
|
+
|
360
|
+
### Sections
|
138
361
|
|
362
|
+
```ruby
|
363
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
364
|
+
|
365
|
+
webhook_url = 'YOUR INCOMING WEBHOOK URL HERE'
|
366
|
+
|
367
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
368
|
+
m.url = webhook_url
|
369
|
+
m.text = 'Message with sections!'
|
370
|
+
m.sections = [
|
371
|
+
{
|
372
|
+
'text': 'Lorem ipsum vastium',
|
373
|
+
'activityTitle': 'John Smith',
|
374
|
+
'activitySubtitle': '01/01/1990, 11:45AM',
|
375
|
+
'activityImage': 'https://connectorsdemo.azurewebsites.net/images/MSC12_Oscar_002.jpg',
|
376
|
+
'facts': [
|
377
|
+
{ 'name': 'Repository:', 'value': 'my-repo' },
|
378
|
+
{ 'name': 'Issue #:', 'value': '123456789' }
|
379
|
+
]
|
380
|
+
}
|
381
|
+
]
|
382
|
+
end
|
383
|
+
|
384
|
+
message.send
|
139
385
|
```
|
140
386
|
|
141
387
|
## Execute tests/specs
|
@@ -153,13 +399,9 @@ docker build -t microsoft_teams_incoming_webhook_ruby_specs .
|
|
153
399
|
docker run -v $(pwd):/app/ -it microsoft_teams_incoming_webhook_ruby_specs
|
154
400
|
```
|
155
401
|
|
156
|
-
##
|
157
|
-
|
158
|
-
...
|
159
|
-
|
160
|
-
## Another similar gems for reference
|
402
|
+
## Similar gems for reference
|
161
403
|
|
162
|
-
There are similar open source libraries that shares the same purpose of this gem, such as:
|
404
|
+
There are similar and great open source libraries that shares the same purpose of this gem, such as:
|
163
405
|
|
164
406
|
- https://github.com/toririn/teams_incoming_clients
|
165
407
|
- https://github.com/shirts/microsoft-teams-ruby
|