File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
moderations/lib/src/usecase Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import type {
12
12
GetMessagesInAConversationRoute ,
13
13
SendMessageInAConversationRoute ,
14
14
UpdateConversationMetaRoute ,
15
+ UpdateConversationStateRoute ,
15
16
} from "@numerique-gouv/crisp/router/conversation" ;
16
17
import type { OperatorsRouter } from "@numerique-gouv/crisp/router/operators" ;
17
18
import { z } from "zod" ;
@@ -111,4 +112,15 @@ export async function create_conversation(
111
112
return { session_id } ;
112
113
}
113
114
115
+ export function MarkConversationAsResolved ( config : Config ) {
116
+ return async function mark_conversation_as_resolved ( session_id : string ) {
117
+ await fetch_crisp < UpdateConversationStateRoute > ( config , {
118
+ endpoint : `/v1/website/${ config . website_id } /conversation/${ session_id } /state` ,
119
+ method : "PATCH" ,
120
+ searchParams : { } ,
121
+ body : { state : "resolved" } ,
122
+ } ) ;
123
+ } ;
124
+ }
125
+
114
126
export type get_crisp_mail_dto = Awaited < ReturnType < typeof get_crisp_mail > > ;
Original file line number Diff line number Diff line change 2
2
3
3
import { NotFoundError } from "@~/app.core/error" ;
4
4
import { z_username } from "@~/app.core/schema/z_username" ;
5
- import { get_user , is_crisp_ticket , send_message } from "@~/crisp.lib" ;
5
+ import {
6
+ get_user ,
7
+ is_crisp_ticket ,
8
+ MarkConversationAsResolved ,
9
+ send_message ,
10
+ } from "@~/crisp.lib" ;
6
11
import { get_full_ticket , send_zammad_response } from "@~/zammad.lib" ;
7
12
import {
8
13
ARTICLE_TYPE ,
@@ -57,6 +62,14 @@ async function respond_in_conversation(
57
62
user,
58
63
session_id : moderation . ticket_id ,
59
64
} ) ;
65
+
66
+ // HACK(douglasduteil): Wait for the message to be sent
67
+ // Crisp seems to have a delay between the message being sent and the state being updated
68
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1_000 ) ) ;
69
+
70
+ const mark_conversation_as_resolved =
71
+ MarkConversationAsResolved ( crisp_config ) ;
72
+ await mark_conversation_as_resolved ( moderation . ticket_id ) ;
60
73
}
61
74
62
75
async function respond_to_zammad_ticket (
You can’t perform that action at this time.
0 commit comments