Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export default function main() {
comment,
promptId,
promptedQuestion,
source,
}: Feedback) {
checkKey();
if (!featureId) err("No featureId provided");
Expand All @@ -247,6 +248,7 @@ export default function main() {
promptId,
question,
promptedQuestion,
source: source ?? "sdk",
};

const res = await request(`${getUrl()}/feedback`, payload);
Expand Down Expand Up @@ -383,6 +385,7 @@ export default function main() {
promptId: message.promptId,
question: reply.question,
promptedQuestion: message.question,
source: "prompt",
});

completionHandler();
Expand Down Expand Up @@ -470,6 +473,7 @@ export default function main() {
featureId: options.featureId,
userId: options.userId,
companyId: options.companyId,
source: "widget",
...data,
});

Expand All @@ -482,6 +486,7 @@ export default function main() {
featureId: options.featureId,
userId: options.userId,
companyId: options.companyId,
source: "widget",
...data,
});

Expand Down
8 changes: 8 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ export type Feedback = {
* feedback.
*/
promptId?: FeedbackPrompt["promptId"];

/**
* Source of the feedback, depending on how the user was asked
* - `prompt` - Feedback submitted by a Live Satisfaction prompt
* - `widget` - Feedback submitted via `requestFeedback`
* - `sdk` - Feedback submitted via `feedback`
*/
source?: "prompt" | "sdk" | "widget";
};

export type FeedbackPrompt = {
Expand Down
1 change: 1 addition & 0 deletions test/e2e/acceptance.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ test("Acceptance", async () => {
featureId: "featureId1",
score: 5,
comment: "test!",
source: "sdk",
})
.reply(200);

Expand Down
3 changes: 3 additions & 0 deletions test/e2e/feedback-widget.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ test("Sends a request when choosing a score immediately", async ({ page }) => {
score: expectedScore,
question: "baz",
userId: "foo",
source: "widget",
});
});

Expand Down Expand Up @@ -251,6 +252,7 @@ test("Updates the score on every change", async ({ page }) => {
question: "baz",
score: 3,
userId: "foo",
source: "widget",
});
});

Expand Down Expand Up @@ -309,6 +311,7 @@ test("Sends a request with both the score and comment when submitting", async ({
featureId: "featureId1",
feedbackId: "123",
userId: "foo",
source: "widget",
});
});

Expand Down
2 changes: 2 additions & 0 deletions test/usage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe("usage", () => {
comment: "Sunt bine!",
question: "Cum esti?",
promptedQuestion: "How are you?",
source: "sdk",
})
.reply(200);

Expand Down Expand Up @@ -683,6 +684,7 @@ describe("feedback state management", () => {
score: 5,
question: "Cum esti?",
promptedQuestion: "How are you?",
source: "prompt",
})
.reply(200, {
feedbackId: "feedback123",
Expand Down