Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core)!: added basic message sent event #507

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import type { BasicMessage } from './messages'
import type { BasicMessageRecord } from './repository'

export enum BasicMessageEventTypes {
BasicMessageReceived = 'BasicMessageReceived',
BasicMessageStateChanged = 'BasicMessageStateChanged',
}

export interface BasicMessageReceivedEvent extends BaseEvent {
type: typeof BasicMessageEventTypes.BasicMessageReceived
export interface BasicMessageStateChangedEvent extends BaseEvent {
type: typeof BasicMessageEventTypes.BasicMessageStateChanged
payload: {
message: BasicMessage
basicMessageRecord: BasicMessageRecord
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { InboundMessageContext } from '../../../agent/models/InboundMessageContext'
import type { ConnectionRecord } from '../../connections/repository/ConnectionRecord'
import type { BasicMessageReceivedEvent } from '../BasicMessageEvents'
import type { BasicMessageStateChangedEvent } from '../BasicMessageEvents'
import type { BasicMessageTags } from '../repository'

import { Lifecycle, scoped } from 'tsyringe'
Expand Down Expand Up @@ -33,6 +33,10 @@ export class BasicMessageService {
})

await this.basicMessageRepository.save(basicMessageRecord)
this.eventEmitter.emit<BasicMessageStateChangedEvent>({
type: BasicMessageEventTypes.BasicMessageStateChanged,
payload: { message: basicMessage, basicMessageRecord },
})

return basicMessage
}
Expand All @@ -50,8 +54,8 @@ export class BasicMessageService {
})

await this.basicMessageRepository.save(basicMessageRecord)
this.eventEmitter.emit<BasicMessageReceivedEvent>({
type: BasicMessageEventTypes.BasicMessageReceived,
this.eventEmitter.emit<BasicMessageStateChangedEvent>({
type: BasicMessageEventTypes.BasicMessageStateChanged,
payload: { message, basicMessageRecord },
})
}
Expand Down