| 1 | import type { WebhookFormat } from './index.js'; |
| 2 | |
| 3 | /** Slack incoming webhooks: https://docs.slack.dev/messaging/sending-messages-using-incoming-webhooks */ |
| 4 | export const slack: |
| 5 | matches: (url) |
| 6 | url.hostname === |
| 7 | // Slack honours username and icon_url only for webhooks made before Slack apps; an app's webhook posts as the app. |
| 8 | render: ({ context |
| 9 | username: sender.name |
| 10 | icon_url: sender.iconUrl |
| 11 | text: [ |
| 12 | `[${escape(context |
| 13 | ...(excerpt ? |
| 14 | ].join('\n' |
| 15 | unfurl_links: false, |
| 16 | }), |
| 17 | }; |
| 18 | |
| 19 | // Slack's only escapes; they also keep user text from forming `<!channel>` or a link. |
| 20 | function escape(text: |
| 21 | return text |
| 22 | .replaceAll('&', |
| 23 | .replaceAll('<', |
| 24 | .replaceAll('>', |
| 25 | } |