Skip to content

Commit

Permalink
feat(feedback): submit browser
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbyheart committed Sep 27, 2024
1 parent 5d3dac8 commit d208466
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 8 additions & 3 deletions features/Feedback.feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ When I `POST` to `${APIURL}/feedback` with
{
"email": "${email}",
"stars": 4,
"suggestion": "None, everything worked well!"
"suggestion": "None, everything worked well!",
"browser": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
}
```

Expand All @@ -48,12 +49,16 @@ content-type: application/json; charset=utf-8
{
"facts": [
{
"name": "Rating:",
"name": "Rating",
"value": "★★★★☆"
},
{
"name": "Email:",
"name": "Email",
"value": "${email}"
},
{
"name": "Browser",
"value": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
}
],
"text": "None, everything worked well!"
Expand Down
11 changes: 8 additions & 3 deletions lambda/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ const InputSchema = Type.Object({
stars: Type.Integer({ minimum: 1, maximum: 5, title: 'Star rating' }),
suggestion: Type.String({ minLength: 1, title: 'Suggestion' }),
email: Type.RegExp(/.+@.+/, { title: 'Email' }),
browser: Type.String({ minLength: 1, title: 'Non-empty string' }),
})

const h = async (
event: APIGatewayProxyEventV2,
context: ValidInput<typeof InputSchema> & Context,
): Promise<APIGatewayProxyResultV2> => {
const { stars, email, suggestion } = context.validInput
const { stars, email, suggestion, browser } = context.validInput

const res = await fetch(settings.webhookURL, {
method: 'POST',
Expand All @@ -54,13 +55,17 @@ const h = async (
{
facts: [
{
name: 'Rating:',
name: 'Rating',
value: '★'.repeat(stars) + '☆'.repeat(5 - stars),
},
{
name: 'Email:',
name: 'Email',
value: email,
},
{
name: 'Browser',
value: browser,
},
],
text: suggestion,
},
Expand Down

0 comments on commit d208466

Please sign in to comment.