@stacksjs/chat 0.69.4 → 0.70.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.
package/dist/slack.d.ts CHANGED
@@ -1 +1,70 @@
1
- export type {}
1
+ import type { ChatMessage, ChatOptions, ChatResult } from '@stacksjs/types';
2
+
3
+ export declare class SlackDriver extends BaseChatDriver {
4
+ public name = 'slack'
5
+ private provider: SlackProvider
6
+
7
+ constructor() {
8
+ super()
9
+ const env = config.services.slack
10
+
11
+ this.provider = new SlackProvider({
12
+ applicationId: env?.appId ?? '',
13
+ clientId: env?.clientId ?? '',
14
+ secretKey: env?.secret ?? '',
15
+ })
16
+ }
17
+
18
+ public async send(message: ChatMessage, options?: ChatOptions): Promise<ChatResult> {
19
+ const logContext = {
20
+ provider: this.name,
21
+ to: message.to,
22
+ subject: message.subject || 'No subject',
23
+ }
24
+
25
+ log.info('Sending message via Slack...', logContext)
26
+
27
+ try {
28
+ this.validateMessage(message)
29
+
30
+ const payload = {
31
+ ...message,
32
+ ...options,
33
+ }
34
+
35
+ const response = await this.sendWithRetry(payload)
36
+ return this.handleSuccess(message, response.id)
37
+ }
38
+ catch (error) {
39
+ return this.handleError(error, message)
40
+ }
41
+ }
42
+
43
+ private async sendWithRetry(payload: any, attempt = 1): Promise<any> {
44
+ try {
45
+ const response = await this.provider.sendMessage(payload)
46
+
47
+ log.info(`[${this.name}] Message sent successfully`, {
48
+ attempt,
49
+ messageId: response.id,
50
+ })
51
+
52
+ return response
53
+ }
54
+ catch (error) {
55
+ if (attempt < (config.services.slack?.maxRetries ?? 3)) {
56
+ const retryTimeout = config.services.slack?.retryTimeout ?? 1000
57
+ log.warn(`[${this.name}] Message send failed, retrying (${attempt}/${config.services.slack?.maxRetries ?? 3})`)
58
+ await new Promise(resolve => setTimeout(resolve, retryTimeout))
59
+ return this.sendWithRetry(payload, attempt + 1)
60
+ }
61
+ throw error
62
+ }
63
+ }
64
+ }
65
+ export declare const driver: unknown;
66
+ export declare function send(message: ChatMessage, options?: ChatOptions): Promise<ChatResult>;
67
+
68
+ export { SlackDriver as Driver }
69
+
70
+ export default SlackDriver;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/chat",
3
3
  "type": "module",
4
- "version": "0.69.4",
4
+ "version": "0.70.0",
5
5
  "description": "Easily interact with chat APIs.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": ["Chris Breuer <chris@stacksjs.org>"],
@@ -33,11 +33,14 @@
33
33
  "typecheck": "bun tsc --noEmit",
34
34
  "prepublishOnly": "bun run build"
35
35
  },
36
+ "dependencies": {
37
+ "@novu/slack": "^0.24.1"
38
+ },
36
39
  "devDependencies": {
37
- "@stacksjs/cli": "0.69.2",
38
- "@stacksjs/config": "0.69.2",
39
- "@stacksjs/development": "0.69.2",
40
- "@stacksjs/error-handling": "0.69.2",
41
- "@stacksjs/types": "0.69.2"
40
+ "@stacksjs/cli": "0.70.0",
41
+ "@stacksjs/config": "0.70.0",
42
+ "@stacksjs/development": "0.70.0",
43
+ "@stacksjs/error-handling": "0.70.0",
44
+ "@stacksjs/types": "0.70.0"
42
45
  }
43
46
  }