| 45 | |
| 46 | /** What reached the consumer, by kind. */ |
| 47 | const makeRecorder = (options?: { |
| 48 | readonly command?: () => Effect.Effect<ChatInteraction.CommandReply> |
| 49 | readonly click?: Effect.Effect<void> |
| 50 | readonly handle?: Effect.Effect<void, NotAccepted> |
| 51 | }) => { |
| 52 | const events: Array<ChatEvent.ChatEvent> = [] |
| 53 | const clicks: Array<ChatInteraction.ButtonClicked | ChatInteraction.SelectChanged> = [] |
| 54 | const commands: Array<ChatInteraction.CommandInvoked> = [] |
| 55 | const refused: Array<ChatError> = [] |
| 56 | const unhandled: Array<Schema.Json> = [] |
| 57 | const handler = ChatHandler.of({ |
| 58 | handle: (event) => options?.handle ?? Effect.sync(() => void events.push(event)) |
| 59 | }) |
| 60 | const interactions = ChatInteraction.Handler.of({ |
| 61 | click: (event) => Effect.as(options?.click ?? Effect.sync(() => void clicks.push(event)), ChatInteraction.ack), |
| 62 | submit: () => Effect.succeed(ChatInteraction.close), |
| 63 | command: (event) => |
| 64 | Effect.andThen( |
| 65 | Effect.sync(() => void commands.push(event)), |
| 66 | options?.command?.() ?? Effect.succeed(ChatInteraction.ack) |
| 67 | ), |
| 68 | refused: (_, error) => Effect.sync(() => void refused.push(error)) |
| 69 | }) |
| 70 | const onUnhandled = (update: Schema.Json) => Effect.sync(() => void unhandled.push(update)) |
| 71 | return { events, clicks, commands, refused, unhandled, handler, interactions, onUnhandled } |
| 72 | } |
| 73 | |
| 74 | type Recorder = ReturnType<typeof makeRecorder> |
| 75 | |