Skip to content

Commit 25bbd44

Browse files
committed
feat: update serverless cookie response to vary on count
1 parent 24baf98 commit 25bbd44

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

serverless/examples/cookies/state-long/state-long-function.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ exports.handler = (context, event, callback) => {
88
// always strings, so you'll need to convert the count to a number
99
const count = Number(event.request.cookies.count) || 0;
1010

11-
twiml.message(`Your current count is ${count}`);
11+
// Return a dynamic message based on if this is the first message or not
12+
const message =
13+
count > 0
14+
? `Your current count is ${count}`
15+
: 'Hello, thanks for the new message!';
16+
17+
twiml.message(message);
1218

1319
response
1420
// Add the stringified TwiML to the response body

serverless/examples/cookies/state/state-function.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ exports.handler = (context, event, callback) => {
88
// always strings, so you'll need to convert the count to a number
99
const count = Number(event.request.cookies.count) || 0;
1010

11-
twiml.message(`Your current count is ${count}`);
11+
// Return a dynamic message based on if this is the first message or not
12+
const message =
13+
count > 0
14+
? `Your current count is ${count}`
15+
: 'Hello, thanks for the new message!';
16+
17+
twiml.message(message);
1218

1319
response
1420
// Add the stringified TwiML to the response body

0 commit comments

Comments
 (0)