Skip to content

Commit

Permalink
feat: List webhook types
Browse files Browse the repository at this point in the history
  • Loading branch information
Negan1911 committed Nov 29, 2021
1 parent 7a2a918 commit 5856bc1
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lerna-debug.log*
# Graphql generated files
*.graphql
index.ts
types.ts
plugins/codegen-build-operations/index.js

# Diagnostic reports (https://nodejs.org/api/report.html)
Expand Down
68 changes: 68 additions & 0 deletions WebhookTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type * as ClientAPI from './types'

export type Events = {
/**
* @protected - Only used internally.
* Used when triggering a unfurl completion
*/
'unfurl:resolve': {
name: 'unfurl:resolve'
messageId: string
}
/**
* Event received when a user is trying to
* authenticate and webhook authentication is set.
*/
'user:authenticate': {
token: string
visitorId: string
name: 'user:authenticate'
attributes?: Array<ClientAPI.VisitorAttributeCategoryInput>
}
/**
* Triggered when a visitor starts a new conversation.
*/
'visitor:new-conversation': {
name: 'visitor:new-conversation'
conversation: ClientAPI.Conversation
}
/**
* Triggered when a visitor posts a new message.
*/
'visitor:message': {
name: 'visitor:message'
message: ClientAPI.ConversationItem
}
/**
* Triggered when a operator answers a visitor message.
*/
'operator:message': {
name: 'operator:message'
message: ClientAPI.ConversationItem
}
/**
* Triggered when an operator closes a conversation.
*/
'operator:close-conversation': {
name: 'operator:close-conversation'
conversation: ClientAPI.Conversation
}
/**
* Triggered when an operator moves a conversation to a new inbox.
*/
'operator:move-conversation': {
name: 'operator:move-conversation'
from: ClientAPI.Inbox
to: ClientAPI.Inbox
conversation: ClientAPI.Conversation
}
/**
* Triggered when a visitor clicks a button that has a callback.
*/
'visitor:clicked-button': {
name: 'visitor:clicked-button'
conversation: ClientAPI.Conversation
message: ClientAPI.ConversationItem
button: ClientAPI.ConversationItem['buttons'][0]
}
}
4 changes: 4 additions & 0 deletions codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ hooks:
- ./node_modules/.bin/tsc plugins/codegen-build-operations/index.ts --esModuleInterop

generates:
'./types.ts':
plugins:
- typescript

'./index.ts':
plugins:
- typescript:
Expand Down
13 changes: 13 additions & 0 deletions sdk.template.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import crypto from 'crypto'
import fetch from 'cross-fetch'
import { Events } from './WebhookTypes'

type GraphQLError = {
message: string
Expand All @@ -13,6 +14,18 @@ type Request<key extends string | number | symbol> = {
variables: Record<string, unknown>
}

/**
* Types for webhook events
*/
export type WebhookEvent<T extends keyof Events> = {
/** ISODate of the timestamp of the request */
timestamp: string
/** Name of the event being received */
name: Events[T]['name']
/** Data of the event being received */
payload: Events[T]
}

class AuthenticationError extends Error {
constructor(message: string) {
super(message)
Expand Down

0 comments on commit 5856bc1

Please sign in to comment.