1- import type { NotificationUserBeaconOnEpicCommentCreated , TicketMessageCreated } from '@roll-stack/essence'
1+ import type { EventHandlerMap , NotificationUserBeaconOnEpicCommentCreated , TicketMessageCreated } from '@roll-stack/essence'
22import { db } from '@roll-stack/database'
3- import { queue } from '@roll-stack/essence'
3+ import { Events , queue } from '@roll-stack/essence'
44import { useAtriumBot } from '../telegram/atrium-bot'
55import { useWasabiBot } from '../telegram/wasabi-bot'
66
77const { telegram } = useRuntimeConfig ( )
88
99export async function setupConsumers ( ) {
10- return queue . telegram . consume ( async ( msg ) => {
11- if ( msg . type === 'ticketMessageCreated' ) {
12- return handleTicketMessageCreated ( msg as TicketMessageCreated )
13- }
14- if ( msg . type === 'notificationUserBeaconOnEpicCommentCreated' ) {
15- return handleUserBeaconOnEpicCommentCreated ( msg as NotificationUserBeaconOnEpicCommentCreated )
16- }
17-
18- return queue . ignore ( )
19- } )
10+ return queue . consume ( queue . telegram . name , {
11+ [ Events . ticketMessageCreated ] : handleTicketMessageCreated ,
12+ [ Events . notificationUserBeaconOnEpicCommentCreated ] : handleUserBeaconOnEpicCommentCreated ,
13+ } as EventHandlerMap )
2014}
2115
22- async function handleTicketMessageCreated ( msg : TicketMessageCreated ) {
16+ async function handleTicketMessageCreated ( data : TicketMessageCreated [ 'data' ] ) : Promise < boolean > {
2317 try {
2418 // Send Telegram message to Owner user via Wasabi Bot
25- const wasabiUser = await db . telegram . findUserByIdAndBotId ( msg . data . ticketOwnerId , telegram . wasabiBotId )
19+ const wasabiUser = await db . telegram . findUserByIdAndBotId ( data . ticketOwnerId , telegram . wasabiBotId )
2620 if ( wasabiUser ) {
27- const text = `${ msg . data . userName } ${ msg . data . userSurname } : ${ msg . data . userText } `
21+ const text = `${ data . userName } ${ data . userSurname } : ${ data . userText } `
2822 await useWasabiBot ( ) . api . sendMessage ( wasabiUser . telegramId , text )
2923 }
3024
31- return queue . success ( )
25+ return true
3226 } catch ( error ) {
3327 console . error ( error )
34- return queue . fail ( )
28+ return false
3529 }
3630}
3731
38- async function handleUserBeaconOnEpicCommentCreated ( msg : NotificationUserBeaconOnEpicCommentCreated ) {
32+ async function handleUserBeaconOnEpicCommentCreated ( data : NotificationUserBeaconOnEpicCommentCreated [ 'data' ] ) : Promise < boolean > {
3933 try {
4034 // Send Telegram message to Atrium user
41- const atriumUser = await db . telegram . findUserByIdAndBotId ( msg . data . userId , telegram . atriumBotId )
35+ const atriumUser = await db . telegram . findUserByIdAndBotId ( data . userId , telegram . atriumBotId )
4236 if ( atriumUser ) {
4337 const separator = 'zzzzz'
44- const startAppData = `epic${ separator } ${ msg . data . epicId } `
38+ const startAppData = `epic${ separator } ${ data . epicId } `
4539
4640 await useAtriumBot ( )
4741 . api
4842 . sendMessage (
4943 atriumUser . telegramId ,
50- `👋 ${ msg . data . senderName } ${ msg . data . senderSurname } \n${ msg . data . title } \n\n${ msg . data . description } ` ,
44+ `👋 ${ data . senderName } ${ data . senderSurname } \n${ data . title } \n\n${ data . description } ` ,
5145 {
5246 reply_markup : {
5347 inline_keyboard : [ [ {
@@ -59,9 +53,9 @@ async function handleUserBeaconOnEpicCommentCreated(msg: NotificationUserBeaconO
5953 )
6054 }
6155
62- return queue . success ( )
56+ return true
6357 } catch ( error ) {
6458 console . error ( error )
65- return queue . fail ( )
59+ return false
6660 }
6761}
0 commit comments