-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/p-7155-write-docs-for-sla-webhoo…
…k' into p-7155-write-docs-for-sla-webhook
- Loading branch information
Showing
11 changed files
with
62 additions
and
10 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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: 'Webhooks and Typescript' | ||
sidebarTitle: 'Using Typescript' | ||
--- | ||
|
||
When using webhooks with Typescript, you can use a utility called `parsePlainWebhook` in the Typescript SDK to parse the webhook requests. | ||
|
||
This makes sure your code is 100% type safe and that all requests are correctly validated. | ||
|
||
```ts | ||
import Express from 'express'; | ||
import { parsePlainWebhook } from '@team-plain/typescript-sdk'; | ||
|
||
const app = Express(); | ||
|
||
app.post('/handler/', function (req: Express.Request, res: Express.Response) { | ||
const parseResult = parsePlainWebhook(req.body); | ||
|
||
// If this errors it means the request is not valid | ||
// you can safely ignore it! | ||
if (parseResult.error) { | ||
res.status(400); | ||
return; | ||
} | ||
|
||
// This is now fully typed and safe to use. | ||
const webhookBody = parseResult.data; | ||
|
||
// You can use the eventType to filter down to a specific event type | ||
if (webhookBody.payload.eventType === 'thread.thread_created') { | ||
console.log(webhookBody.payload.thread.id); | ||
} | ||
|
||
res.status(200); | ||
}); | ||
``` |
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