Skip to content

Commit

Permalink
Merge pull request #107 from freshworks/revert_stable_build
Browse files Browse the repository at this point in the history
Revert stable build
  • Loading branch information
ShashaankKrishnatray authored Nov 16, 2023
2 parents fbc5fac + 6978b63 commit a0113e2
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/freshchat-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@freshworks-jaya/freshchat-api",
"version": "0.7.33-beta-09",
"version": "0.7.34",
"description": "Provides simple interface for accessing Freshchat's public APIs",
"repository": "[email protected]:freshdesk/jaya-lib.git",
"main": "lib/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/marketplace-models/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@freshworks-jaya/marketplace-models",
"version": "0.1.26",
"version": "0.1.27",
"description": "Provides type definitions for models in marketplace product events",
"repository": "[email protected]:freshdesk/jaya-lib.git",
"main": "lib/index.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/rule-engine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@freshworks-jaya/rule-engine",
"version": "0.17.25-beta-03",
"version": "0.17.26",
"description": "Provides methods to process rules in product events in marketplace app",
"repository": "[email protected]:freshdesk/jaya-lib.git",
"main": "lib/index.js",
Expand Down Expand Up @@ -44,9 +44,9 @@
"typescript": "^4.3.2"
},
"dependencies": {
"@freshworks-jaya/freshchat-api": "0.7.33-beta-09",
"@freshworks-jaya/freshchat-api": "0.7.34",
"@freshworks-jaya/kairos-api": "^0.1.5",
"@freshworks-jaya/marketplace-models": "0.1.26",
"@freshworks-jaya/marketplace-models": "0.1.27",
"@freshworks-jaya/utilities": "^1.0.0",
"@google-cloud/logging": "^9.3.1",
"axios": "^0.21.4",
Expand Down
8 changes: 4 additions & 4 deletions packages/rule-engine/src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ export class Utils {

if (messageParts && messageParts.length) {
messageContent = messageParts
.filter((messagePart) => messagePart.text)
.filter((messagePart) => messagePart.text || messagePart.email)
.map((messagePart) => {
return messagePart.text && messagePart.text.content;
return (messagePart.text && messagePart.text.content) || (messagePart.email && messagePart.email.subject);
})
.join(' ');
}
Expand All @@ -136,7 +136,7 @@ export class Utils {
}

/**
* Gets a concatenated string of messageParts with type 'text'.
* Gets a concatenated string of messageParts with type 'email'.
*/
public static getMessagePartsEmailContent(messageParts: MessagePart[]): string {
let messageContent = '';
Expand Down Expand Up @@ -213,7 +213,7 @@ export class Utils {
} catch (err) {
this.log(productEventPayload, integrations, ErrorCodes.DynamicPlaceholder, {
dynamicPlaceholderKey,
error: err,
error: err as AnyJson,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default async (
accountId: appId,
from: {
email: '[email protected]',
name: 'Freshchat Automations',
name: 'Automated response',
},
html: emailParams.body,
subject: emailParams.subject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default async (
accountId: appId,
from: {
email: '[email protected]',
name: 'Freshchat Automations',
name: 'Automated response',
},
html: conversationHtml,
subject: emailSubject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default (

return Utils.evaluateCondition(
condition.operator,
Utils.getMessagePartsEmailContent((modelProperties.messages && modelProperties.messages[0].message_parts) || []),
Utils.getMessagePartsEmailContent((modelProperties.messages && modelProperties.messages[0]?.message_parts) || []),
condition.value as string,
integrations,
options,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { ProductEventPayload } from '@freshworks-jaya/marketplace-models';
import Freshchat from '@freshworks-jaya/freshchat-api';
import { Integrations, RuleEngineOptions } from '../../models/rule-engine';
import { Utils } from '../../Utils';
import { ErrorCodes, ErrorTypes } from '../../models/error-codes';
import { LogSeverity } from '../../services/GoogleCloudLogging';
import Constants from '../Constants';

export default (
productEventPayload: ProductEventPayload,
integrations: Integrations,
options: RuleEngineOptions,
ruleAlias: string,
): Promise<string> => {
const freshchatApiUrl = integrations.freshchatv2.url;
const freshchatApiToken = integrations.freshchatv2.token;
const freshchat = new Freshchat(freshchatApiUrl, freshchatApiToken, ruleAlias);
const modelProperties = productEventPayload.data.conversation || productEventPayload.data.message;

return freshchat
.getConversationTranscript(
`https://${productEventPayload.domain}`,
modelProperties.app_id,
modelProperties.conversation_id,
{
isFetchUntilLastResolve: true,
isIncludeFreshchatLink: false,
messagesLimit: options.isUseStaticIP
? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP
: Constants.MAX_MESSAGES_TRANSCRIPT,
output: 'paytm_html',
timezoneOffset: integrations.timezoneOffset,
},
{
isExcludePrivate: true,
isExcludeSystem: true,
},
)
.then((transcript) => Promise.resolve(transcript))
.catch((err) => {
Utils.log(
productEventPayload,
integrations,
ErrorCodes.FreshchatPlaceholder,
{
error: {
err,
payload: {
freshchatApiToken,
options: {
messagesLimit: options.isUseStaticIP
? Constants.MAX_MESSAGES_TRANSCRIPT_STATIC_IP
: Constants.MAX_MESSAGES_TRANSCRIPT,
timezoneOffset: integrations.timezoneOffset,
},
},
},
errorType: ErrorTypes.TranscriptLastResolveHtml,
},
LogSeverity.ERROR,
);
return Promise.reject();
});
};
2 changes: 2 additions & 0 deletions packages/rule-engine/src/recommended/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import dynamicPlaceholderTranscriptConvEntireText from './dynamic-placeholders/t
import dynamicPlaceholderTranscriptConvEntireIncludesPrivateSystemText from './dynamic-placeholders/transcript-conv-entire-includes-private-system-text';
import dynamicPlaceholderTranscriptConvSinceLastResolveText from './dynamic-placeholders/transcript-conv-since-last-resolve-text';
import dynamicPlaceholderTranscriptConvSinceLastResolveIncludesPrivateSystemText from './dynamic-placeholders/transcript-conv-since-last-resolve-includes-private-system-text';
import dynamicPlaceholderTranscriptPaytmConvSinceLastResolveHtml from './dynamic-placeholders/transcript-paytm-conv-since-last-resolve-html';

const recommendedPlugins: RulePlugin[] = [
{
Expand Down Expand Up @@ -161,6 +162,7 @@ const recommendedPlugins: RulePlugin[] = [
dynamicPlaceholderTranscriptConvSinceLastResolveIncludesPrivateSystemText,
'transcript.conv_since_last_resolve.text': dynamicPlaceholderTranscriptConvSinceLastResolveText,
'transcript.paytm_conv_entire.html': dynamicPlaceholderTranscriptPaytmConvEntireHtml,
'transcript.paytm_conv_since_last_resolve.html': dynamicPlaceholderTranscriptPaytmConvSinceLastResolveHtml,
},
operators: {
[ConditionOperator.StartsWith]: operatorStartsWith,
Expand Down

0 comments on commit a0113e2

Please sign in to comment.