| 1 | import type { WebhookFormat } from './index.js'; |
| 2 | |
| 3 | /** Microsoft Teams, through a Workflows webhook or a legacy incoming webhook connector; both take an Adaptive Card: https://learn.microsoft.com/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook */ |
| 4 | export const teams: |
| 5 | // A Workflows URL on logic.azure.com is left out: any Azure Logic App has one, and it may want Ghost's JSON. |
| 6 | matches: (url) |
| 7 | url.hostname.endsWith |
| 8 | (url.hostname.endsWith |
| 9 | url.pathname.includes |
| 10 | render: ({ |
| 11 | context, |
| 12 | actor, |
| 13 | action, |
| 14 | url, |
| 15 | excerpt, |
| 16 | commits, |
| 17 | moreCommits, |
| 18 | timestamp, |
| 19 | }) => { |
| 20 | // DATE() and TIME() want RFC 3339 without fractions of a second. |
| 21 | const when = |
| 22 | return { |
| 23 | type: 'message', |
| 24 | attachments: [ |
| 25 | { |
| 26 | contentType: 'application/vnd.microsoft.card.adaptive', |
| 27 | content: { |
| 28 | $schema: 'http://adaptivecards.io/schemas/adaptive-card.json', |
| 29 | type: 'AdaptiveCard', |
| 30 | version: '1.4', |
| 31 | body: [ |
| 32 | { type: 'TextBlock', |
| 33 | actor |
| 34 | ? { |
| 35 | type: 'ColumnSet', |
| 36 | columns: [ |
| 37 | ...(actor.avatarUrl |
| 38 | ? [ |
| 39 | { |
| 40 | type: 'Column', |
| 41 | width: 'auto', |
| 42 | verticalContentAlignment: 'Center', |
| 43 | items: [ |
| 44 | { |
| 45 | type: 'Image', |
| 46 | url: actor.avatarUrl |
| 47 | altText: actor.name |
| 48 | size: 'Small', |
| 49 | style: 'Person', |
| 50 | }, |
| 51 | ], |
| 52 | }, |
| 53 | ] |
| 54 | : []), |
| 55 | { |
| 56 | type: 'Column', |
| 57 | width: 'stretch', |
| 58 | verticalContentAlignment: 'Center', |
| 59 | items: [ |
| 60 | { |
| 61 | type: 'TextBlock', |
| 62 | text: `${actor. |
| 63 | weight: 'Bolder', |
| 64 | wrap: true, |
| 65 | }, |
| 66 | { |
| 67 | type: 'TextBlock', |
| 68 | // Teams shows the date and time in the reader's own zone. |
| 69 | text: `{{DATE(${when |
| 70 | isSubtle: true, |
| 71 | spacing: 'None', |
| 72 | wrap: true, |
| 73 | }, |
| 74 | ], |
| 75 | }, |
| 76 | ], |
| 77 | } |
| 78 | : { |
| 79 | type: 'TextBlock', |
| 80 | text: action, |
| 81 | weight: 'Bolder', |
| 82 | wrap: true, |
| 83 | }, |
| 84 | ...commits.map( |
| 85 | type: 'TextBlock', |
| 86 | text: `[${commit |
| 87 | wrap: true, |
| 88 | spacing: 'Small', |
| 89 | })), |
| 90 | ...(moreCommits > |
| 91 | ? [ |
| 92 | { |
| 93 | type: 'TextBlock', |
| 94 | text: `and ${moreCommits |
| 95 | isSubtle: true, |
| 96 | wrap: true, |
| 97 | }, |
| 98 | ] |
| 99 | : []), |
| 100 | ...(excerpt |
| 101 | ? [{ type: ' |
| 102 | : []), |
| 103 | ], |
| 104 | actions: url |
| 105 | ? [{ type: ' |
| 106 | : [], |
| 107 | }, |
| 108 | }, |
| 109 | ], |
| 110 | }; |
| 111 | }, |
| 112 | }; |