-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from theosli/feature/page/subscription
Subscription feature
- Loading branch information
Showing
31 changed files
with
15,187 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,44 @@ | ||
import { getUserPreferences } from './getUserPreferences'; | ||
import { JSDOM } from 'jsdom'; | ||
import DOMPurify from 'dompurify'; | ||
|
||
export const buildResponse = async (body: any) => { | ||
// Generate a response from AI based on the received email text | ||
const aiResponse = await getUserPreferences(body['TextBody']); | ||
|
||
const window = new JSDOM('').window; | ||
const purify = DOMPurify(window); | ||
const cleanBodyFrom = purify.sanitize(body['From']); | ||
const cleanBodyDate = purify.sanitize(body['Date']); | ||
const cleanBodyTo = purify.sanitize(body['To']); | ||
const cleanBodySubject = purify.sanitize(body['Subject']); | ||
const cleanBodyTextBody = purify.sanitize(body['TextBody']); | ||
const cleanThemes = purify.sanitize( | ||
aiResponse?.themes.length == 1 ? 'theme' : 'themes' | ||
); | ||
|
||
const emailMetadata = ` | ||
-------- Previous Message -------- | ||
From: ${body['From']} | ||
From: ${cleanBodyFrom} | ||
Sent: ${body['Date']} | ||
Sent: ${cleanBodyDate} | ||
To: ${body['To']} | ||
To: ${cleanBodyTo} | ||
Subject: ${body['Subject']} | ||
Subject: ${cleanBodySubject} | ||
${body['TextBody']} | ||
${cleanBodyTextBody} | ||
`; | ||
|
||
if (aiResponse?.themes?.length) { | ||
if (!aiResponse?.themes?.length) { | ||
return `Sorry, we didn't find any preferences in your E-Mail. ${emailMetadata}`; | ||
} | ||
return `Hello! | ||
The following ${aiResponse?.themes.length == 1 ? 'theme' : 'themes'} have been added to your next newsletters : | ||
The following ${cleanThemes} have been added to your next newsletters : | ||
- ${aiResponse?.themes.join('\n - ')} | ||
${emailMetadata}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.