Skip to content

Commit

Permalink
Send notification of feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
kdid committed Jun 28, 2024
1 parent 1b5e2bf commit 2b0df30
Show file tree
Hide file tree
Showing 8 changed files with 1,949 additions and 20 deletions.
558 changes: 544 additions & 14 deletions layers/api_dependencies/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions layers/api_dependencies/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dependencies": {
"@aws-crypto/sha256-browser": "^2.0.1",
"@aws-sdk/client-sfn": "^3.563.0",
"@aws-sdk/client-sns": "^3.606.0",
"@aws-sdk/credential-provider-node": "^3.563.0",
"@honeybadger-io/js": "^4.9.3",
"@smithy/node-http-handler": "^2.5.0",
Expand Down
23 changes: 21 additions & 2 deletions node/src/handlers/post-chat-feedback.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const { wrap } = require("./middleware");
const { PutObjectCommand, S3Client } = require("@aws-sdk/client-s3");
const { SNSClient, PublishCommand } = require("@aws-sdk/client-sns");

const Validator = require("jsonschema").Validator;

const feedbackSchema = {
Expand Down Expand Up @@ -56,6 +58,11 @@ const handler = wrap(async (event) => {
}
await uploadToS3(`${content.sentiment}/${content.context.ref}`, content);

await sendNotification(
`Chat feedback: ${content.sentiment} response`,
JSON.stringify(content, null, 2)
);

return {
statusCode: 200,
headers: { "content-type": "text/plain" },
Expand All @@ -76,7 +83,7 @@ const handler = wrap(async (event) => {
const uploadToS3 = async (key, body) => {
const client = new S3Client({});
const command = new PutObjectCommand({
Bucket: process.env.MEDIA_CONVERT_DESTINATION_BUCKET,
Bucket: process.env.CHAT_FEEDBACK_BUCKET,
Key: key,
Body: JSON.stringify(body, null, 2),
ContentType: "application/json",
Expand All @@ -85,4 +92,16 @@ const uploadToS3 = async (key, body) => {
return await client.send(command);
};

module.exports = { handler };
const sendNotification = async (subject, message) => {
const snsClient = new SNSClient({});
const command = new PublishCommand({
TopicArn: process.env.CHAT_FEEDBACK_TOPIC_ARN,
Subject: subject,
Message: message,
});
const response = await snsClient.send(command);
console.log(response);
return response;
};

module.exports = { handler, uploadToS3 };
Loading

0 comments on commit 2b0df30

Please sign in to comment.