Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rephrase webhook docs #24

Merged
merged 5 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is the documentation for [Plain](https://plain.com) and its API which you can find here:

**https://plain.com/docs**
[**plain.com/docs**](https://plain.com/docs)

They are built using [Mintlify](https://mintlify.com).

Expand All @@ -24,5 +24,5 @@ There are some key language/style choices you should follow (and add to):
- URL is uppercase
- 'backend' not 'back-end'
- Be consistent in which words are used for different groups of people:
- When refering to people who are helped via Plain use the name "customer"
- When refering to people who use Plain to help other people use the name "user"
- When referring to people who are helped via Plain use the name "customer"
- When referring to people who use Plain to help other people use the name "user"
18 changes: 18 additions & 0 deletions api-reference/graphql/threads/autoresponders.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
Autoresponders
---

Plain provides a native [workspace level autoresponder](/autoresponders), however for more complex cases you may want to implement your own custom autoresponder.

To achieve this you can set up endpoint(s) to be notified of one or more [Webhooks](/api-reference/webhooks) from Plain. We would typically recommend listening for the [Thread created](/api-reference/webhooks/thread-created) webhook as this will allow you the option of responding to any Thread whether it was created via email, Slack or a contact form.
DLeyland marked this conversation as resolved.
Show resolved Hide resolved

If you want to only reply to emails, you can use the [Email received](/api-reference/webhooks/thread-email-received) webhook. This will trigger for all emails, not just the first one in a thread, so you should check the `isStartOfThread` field provided in the webhook payload to ensure you only reply to the first message.

<Warning>
Note that if you subscribe to both `thread.thread_created` and `thread.email_received` you may
receive two events for the same email, since we create a new thread for emails which don't belong
to an existing thread. In order to avoid replying to the same message twice please check the
`isStartOfThread` field in the `thread.email_received` payload.
</Warning>

Once you have received an event and decided how to respond you can use the `replyToThread` mutation to send a reply back to the customer. See our [API explorer](https://app.plain.com/developer/api-explorer/) or [Typescript SDK](https://github.com/team-plain/typescript-sdk/) for more details.
12 changes: 1 addition & 11 deletions api-reference/webhooks/thread-created.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@ title: 'Thread created'

This event is fired when a new thread is created in your workspace.

You can subscribe to this event **if you want to build an auto-responder**. To do so, when you receive this event, use the `replyToThread` mutation to send a reply back to the customer.

<Warning>
Every email you receive in your workspace is linked to a thread. If we cannot find a matching
thread for an email, we will create one. When this happens, you may receive two events:
`thread.thread_created` and
[`thread.email_received`](/api-reference/webhooks/thread-email-received) (depending on your
webhook target event subscriptions). If you do, and you only care about emails which are not the
first message of the thread, please check the `isStartOfThread` in the
[`thread.email_received`](/api-reference/webhooks/thread-email-received) payload.
</Warning>
You can subscribe to this event if you want to build an [autoresponder](/api-reference/graphql/threads/autoresponders).

## Schema

Expand Down
7 changes: 0 additions & 7 deletions api-reference/webhooks/thread-email-received.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ title: 'Email received'

This event is fired when an email is received in your workspace.

<Warning>
An important field that might go unnoticed is `isStartOfThread`. This will tell you if this email
is the first message of a thread or not, which is useful if you want to build some auto-reply
logic. If you want to build an auto-responder that *only replies* to the first message of a
thread, please check [`thread.thread_created`](/api-reference/webhooks/thread-created) instead.
</Warning>

## Schema

[**View JSON Schema →**](https://json-schema.app/view/%23%2Fdefinitions%2FcustomerCreatedPayload?url=https%3A%2F%2Fcore-api.uk.plain.com%2Fwebhooks%2Fschema.json)
Expand Down
7 changes: 0 additions & 7 deletions api-reference/webhooks/thread-email-sent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ title: 'Email sent'

This event is fired when an email is sent in your workspace.

<Warning>
An important field that might go unnoticed is `isStartOfThread`. This will tell you if this email
is the first message of a thread or not, which is useful if you want to build some auto-reply
logic. If you want to build an auto-responder that *only replies* to the first message of a
thread, please check [`thread.thread_created`](/api-reference/webhooks/thread-created) instead.
</Warning>

## Schema

[**View JSON Schema →**](https://json-schema.app/view/%23%2Fdefinitions%2FcustomerCreatedPayload?url=https%3A%2F%2Fcore-api.uk.plain.com%2Fwebhooks%2Fschema.json)
Expand Down
4 changes: 3 additions & 1 deletion autoresponders.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ An autoresponder can be useful in situations of acute support load, such as duri
Autoresponder messages are best kept short and personable without too many links or formatting. Messages which are too long and scripted will often just be ignored as they are too obviously automated.

<Warning>
Please be aware that autresponders are not yet supported for threads created via Slack.
Please be aware that autoresponders are not yet supported for threads created via Slack.
</Warning>

You can also leverage Plain's powerful API and webhooks to build custom interactive autoresponders, see [Thread autoresponders](/api-reference/graphql/threads/autoresponders) for more details.
3 changes: 2 additions & 1 deletion mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@
"api-reference/graphql/threads",
"api-reference/graphql/threads/create",
"api-reference/graphql/threads/assignment",
"api-reference/graphql/threads/status-changes"
"api-reference/graphql/threads/status-changes",
"api-reference/graphql/threads/autoresponders"
]
},
"api-reference/graphql/pagination",
Expand Down
Loading