Skip to content

Commit

Permalink
update webhook doc
Browse files Browse the repository at this point in the history
  • Loading branch information
djyde committed Apr 26, 2021
1 parent 778c8e0 commit 5bd1ad3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
10 changes: 6 additions & 4 deletions pages/dashboard/project/[projectId].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AlertDialog, AlertDialogBody, AlertDialogContent, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, Box, Breadcrumb, BreadcrumbItem, BreadcrumbLink, Button, Center, Checkbox, Code, Container, Divider, Flex, FormControl, Heading, HStack, Input, Link, Spacer, Spinner, StackDivider, Switch, Tab, TabList, TabPanel, TabPanels, Tabs, Tag, Text, Textarea, toast, useDisclosure, useToast, VStack } from '@chakra-ui/react'
import { AlertDialog, AlertDialogBody, AlertDialogContent, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, Box, Breadcrumb, BreadcrumbItem, BreadcrumbLink, Button, Center, Checkbox, Code, Container, Divider, Flex, FormControl, Heading, HStack, Input, InputGroup, InputRightElement, Link, Spacer, Spinner, StackDivider, Switch, Tab, TabList, TabPanel, TabPanels, Tabs, Tag, Text, Textarea, toast, useDisclosure, useToast, VStack } from '@chakra-ui/react'
import { Comment, Page, Project } from '@prisma/client'
import { session, signIn } from 'next-auth/client'
import { useRouter } from 'next/router'
Expand Down Expand Up @@ -418,10 +418,12 @@ function Settings(props: {
<Switch onChange={onChangeEnableWebhook} defaultChecked={props.project.enableWebhook} />
<Heading size="md">Webhook</Heading>
</HStack>
<HStack>
<InputGroup>
<Input defaultValue={props.project.webhook} type="text" ref={webhookInputRef}></Input>
<Button isLoading={updateWebhookUrlMutation.isLoading} onClick={onSaveWebhookUrl}>Save</Button>
</HStack>
<InputRightElement width='16'>
<Button size="sm" isLoading={updateWebhookUrlMutation.isLoading} onClick={onSaveWebhookUrl}>Save</Button>
</InputRightElement>
</InputGroup>
</VStack>

<Box>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "projects" ADD COLUMN "webhook" TEXT,
ADD COLUMN "enableWebhook" BOOLEAN;
5 changes: 4 additions & 1 deletion prisma/pgsql/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ model User {
Comment Comment[]
enableNewCommentNotification Boolean? @default(true) @map(name: "enable_new_comment_notification")
notificationEmail String? @map(name: "notification_email")
notificationEmail String? @map(name: "notification_email")
@@map(name: "users")
}
Expand Down Expand Up @@ -92,6 +92,9 @@ model Project {
enableNotification Boolean? @default(true) @map(name: "enable_notification")
webhook String?
enableWebhook Boolean?
@@map(name: "projects")
}

Expand Down
1 change: 1 addition & 0 deletions public/doc/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
- [Notification](/features/notification.md)
- **Advanced**
- [JS SDK Reference](/advanced/sdk.md)
- [Webhook Reference](/advanced/webhook.md)
- [i18n](/advanced/i18n.md)
- [**Contributing Guide**](/contributing.md)
30 changes: 30 additions & 0 deletions public/doc/advanced/webhook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Webhook

In addition to get new comment notification from Email, we also provide Webhook.

## Enable

To enable webhook for project, in `Project` -> `Settings`, save your webhook url and turn on the switch button.

![](../images/enable_webhook.png ':size=500')

## Reference

### New comment

When new comment comes in, Cusdis will make a `POST` request to your webhook, with below data:

```js
{
"type": "new_comment",
"data": {
"by_nickname": "xxx",
"by_email": "xxx",
"content": "xxx",
"page_id": "xxx",
"page_title": "xxx", // page title, maybe NULL
"project_title": "haha", // project title
"approve_link": "" // use this link to approve this comment without login
}
}
```
Binary file added public/doc/images/enable_webhook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5bd1ad3

Please sign in to comment.