File tree 2 files changed +33
-3
lines changed
apps/api/src/chat/services
libs/definitions/src/integration-definitions/xmtp
2 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import { JobNonRetriableError } from '@app/common/errors/job-non-retriable-error
2
2
import { wait } from '@app/common/utils/async.utils'
3
3
import { XmtpLib } from '@app/definitions/integration-definitions/xmtp/xmtp.lib'
4
4
import { getWalletName } from '@app/definitions/utils/address.utils'
5
- import { sendXmtpMessage } from '@chainjet/tools/dist/messages'
6
5
import { InjectQueue , Process , Processor } from '@nestjs/bull'
7
6
import { Logger } from '@nestjs/common'
8
7
import { Interval } from '@nestjs/schedule'
@@ -108,7 +107,12 @@ export class BroadcastConsumer {
108
107
continue
109
108
}
110
109
try {
111
- const message = await sendXmtpMessage ( client , sendTo , campaign . message + '\n\n' + unsubscribeMessage )
110
+ const message = await XmtpLib . sendDirectMessageWithTimeout (
111
+ client ,
112
+ sendTo ,
113
+ campaign . message + '\n\n' + unsubscribeMessage ,
114
+ 10 * 1000 ,
115
+ )
112
116
await this . campaignMessageService . createOne ( {
113
117
campaign : campaign . _id ,
114
118
address : contact . address ,
Original file line number Diff line number Diff line change 1
- import { Client , Conversation } from '@xmtp/xmtp-js'
1
+ import { sendXmtpMessage } from '@chainjet/tools/dist/messages'
2
+ import { Client , Conversation , DecodedMessage } from '@xmtp/xmtp-js'
2
3
import { isAddress } from 'ethers/lib/utils'
3
4
4
5
const clientsCache = new Map < string , Client > ( )
@@ -48,4 +49,29 @@ export const XmtpLib = {
48
49
}
49
50
return xmtpMessage
50
51
} ,
52
+
53
+ sendDirectMessageWithTimeout : async (
54
+ client : Client ,
55
+ sendTo : string ,
56
+ message : string ,
57
+ timeoutMs : number ,
58
+ ) : Promise < DecodedMessage > => {
59
+ let timeoutHandle : NodeJS . Timeout | undefined
60
+
61
+ const timeoutPromise = new Promise < DecodedMessage > ( ( _ , reject ) => {
62
+ timeoutHandle = setTimeout ( ( ) => {
63
+ reject ( new Error ( 'Message sending timed out' ) )
64
+ } , timeoutMs )
65
+ } )
66
+
67
+ const sendMessagePromise : Promise < DecodedMessage > = sendXmtpMessage ( client , sendTo , message )
68
+
69
+ try {
70
+ return await Promise . race ( [ sendMessagePromise , timeoutPromise ] )
71
+ } catch ( error ) {
72
+ throw error
73
+ } finally {
74
+ clearTimeout ( timeoutHandle )
75
+ }
76
+ } ,
51
77
}
You can’t perform that action at this time.
0 commit comments