Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"IPostLivechatRoomClosed",
"IUIKitLivechatInteractionHandler"
],
"commitHash": "47a27ed35ee6fe974a5043fe82d49b6866a63827"
"commitHash": "2332c0c9abada4f27b9a3c3666f99c65883f1f99"
}
14 changes: 11 additions & 3 deletions endpoints/IncomingEndpoint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HttpStatusCode, IHttp, IModify, IPersistence, IRead } from '@rocket.chat/apps-engine/definition/accessors';
import { ApiEndpoint, IApiEndpointInfo, IApiRequest, IApiResponse } from '@rocket.chat/apps-engine/definition/api';
import { IApp } from '@rocket.chat/apps-engine/definition/IApp';
import { ILivechatRoom } from '@rocket.chat/apps-engine/definition/livechat';
import { DialogflowRequestType, IDialogflowMessage } from '../enum/Dialogflow';
import { EndpointActionNames, IActionsEndpointContent } from '../enum/Endpoints';
Expand All @@ -25,15 +26,16 @@ export class IncomingEndpoint extends ApiEndpoint {
this.app.getLogger().info(Logs.ENDPOINT_RECEIVED_REQUEST);

try {
const { statusCode = HttpStatusCode.OK, data = null } = await this.processRequest(read, modify, persis, http, request.content);
const { statusCode = HttpStatusCode.OK, data = null } = await this.processRequest(this.app, read, modify, persis, http, request.content);
return createHttpResponse(statusCode, { 'Content-Type': Headers.CONTENT_TYPE_JSON }, { ...data ? { ...data } : { result: Response.SUCCESS } });
} catch (error) {
this.app.getLogger().error(Logs.ENDPOINT_REQUEST_PROCESSING_ERROR, error);
return createHttpResponse(HttpStatusCode.INTERNAL_SERVER_ERROR, { 'Content-Type': Headers.CONTENT_TYPE_JSON }, { error: error.message });
}
}

private async processRequest(read: IRead,
private async processRequest(app: IApp,
read: IRead,
modify: IModify,
persistence: IPersistence,
http: IHttp,
Expand Down Expand Up @@ -74,7 +76,13 @@ export class IncomingEndpoint extends ApiEndpoint {
}

try {
const response: IDialogflowMessage = await Dialogflow.sendRequest(http, read, modify, sessionId, event, DialogflowRequestType.EVENT);
const response: IDialogflowMessage = await Dialogflow.sendRequest(http,
read,
modify,
persistence,
sessionId,
event,
DialogflowRequestType.EVENT);
// widechat specific change
// await createDialogflowMessage(sessionId, read, modify, response, this.app);
// await handlePayloadActions(this.app, read, modify, http, persistence, sessionId, vToken, response);
Expand Down
21 changes: 14 additions & 7 deletions handler/PostMessageSentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { AppSetting } from '../config/Settings';
import { DialogflowRequestType, IDialogflowMessage, IDialogflowQuickReplies, LanguageCode, Message } from '../enum/Dialogflow';

import { Logs } from '../enum/Logs';
import { Global } from '../Global';
import { botTypingListener, removeBotTypingListener } from '../lib//BotTyping';
import { Dialogflow } from '../lib/Dialogflow';
import { getErrorMessage } from '../lib/Helper';
import { getError, getErrorMessage } from '../lib/Helper';
import { createDialogflowMessage, createMessage, removeQuotedMessage } from '../lib/Message';
import { handleResponse } from '../lib/payloadAction';
import { getIsProcessingMessage, getIsQueueWindowActive, getRoomAssoc, retrieveDataByAssociation, setIsProcessingMessage, setQueuedMessage } from '../lib/Persistence';
import { getIsProcessingMessage, getIsQueueWindowActive, getRoomAssoc, retrieveDataByAssociation, setIsProcessingMessage, setIsQueueWindowActive, setQueuedMessage } from '../lib/Persistence';
import { handleParameters } from '../lib/responseParameters';
import { closeChat, performHandover, updateRoomCustomFields } from '../lib/Room';
import { cancelAllEventSchedulerJobForSession, cancelAllSessionMaintenanceJobForSession } from '../lib/Scheduler';
Expand Down Expand Up @@ -126,7 +127,7 @@ export class PostMessageSentHandler {
await setIsProcessingMessage(this.read, this.persistence, rid, true);
await cancelAllEventSchedulerJobForSession(this.modify, rid);
await botTypingListener(this.modify, rid, servedBy.username);
response = (await Dialogflow.sendRequest(this.http, this.read, this.modify, rid, messageText, DialogflowRequestType.MESSAGE));
response = (await Dialogflow.sendRequest(this.http, this.read, this.modify, this.persistence, rid, messageText, DialogflowRequestType.MESSAGE));
await setIsProcessingMessage(this.read, this.persistence, rid, false);
} catch (error) {
await setIsProcessingMessage(this.read, this.persistence, rid, false);
Expand Down Expand Up @@ -198,10 +199,16 @@ export class PostMessageSentHandler {
const defaultLanguageCode = await getLivechatAgentConfig(read, rid, AppSetting.DialogflowAgentDefaultLanguage);

let res: IDialogflowMessage;
res = (await Dialogflow.sendRequest(this.http, this.read, this.modify, rid, {
name: DialogflowChatClosedByVisitorEventName,
languageCode: data.custom_languageCode || defaultLanguageCode || LanguageCode.EN,
}, DialogflowRequestType.EVENT));
res = (await Dialogflow.sendRequest(this.http,
this.read,
this.modify,
this.persistence,
rid,
{
name: DialogflowChatClosedByVisitorEventName,
languageCode: data.custom_languageCode || defaultLanguageCode || LanguageCode.EN,
},
DialogflowRequestType.EVENT));
} catch (error) {
const errorContent = `${Logs.DIALOGFLOW_REST_API_ERROR}: { roomID: ${rid} } ${getErrorMessage(error)}`;
this.app.getLogger().error(errorContent);
Expand Down
Loading