Skip to content

Commit b788dc0

Browse files
authored
Zendesk and Intercom integrations for Docs Agents (#836)
* Start * Auth and configuration * Implement auth * Create or update webhook * Start ingestion of tickets * Dont push empty conversations * Set url for conversations * Handle webhooks * Migrate to latest version of CF runtime * Start intercom * Cleanup * Format * Fix TS error * Format * Fix check command * Improve check to use test env * Fix check not running in env * Publish as v2 * Fix webhook and team listing * Fix request * Format * Add config for staging * Update configs * Install op * Auth 1password * Update descriptions * Test it with credentials * Try running signin * Try again * Fix env
1 parent 71a2df9 commit b788dc0

36 files changed

+1605
-207
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Setup 1Password CLI
2+
description: Install 1Password CLI
3+
inputs:
4+
OP_SERVICE_ACCOUNT_TOKEN:
5+
description: Service account token for 1Password
6+
required: true
7+
runs:
8+
using: 'composite'
9+
steps:
10+
- name: Install 1Password CLI
11+
shell: bash
12+
run: curl -sSfo op.zip
13+
https://cache.agilebits.com/dist/1P/op2/pkg/v2.31.1/op_linux_amd64_v2.31.1.zip
14+
&& unzip -od /usr/local/bin/ op.zip
15+
&& rm op.zip
16+
- name: Setup 1Password CLI
17+
shell: bash
18+
run: op user get --me
19+
env:
20+
OP_SERVICE_ACCOUNT_TOKEN: ${{ inputs.OP_SERVICE_ACCOUNT_TOKEN }}

.github/workflows/production.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ jobs:
2525
uses: oven-sh/setup-bun@v2
2626
with:
2727
bun-version-file: 'package.json'
28+
- name: Setup 1Password CLI
29+
uses: ./.github/composite/setup-1password-op
30+
with:
31+
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
2832
- name: Install dependencies
2933
run: bun install --frozen-lockfile
3034

@@ -42,6 +46,7 @@ jobs:
4246
GITBOOK_TOKEN: ${{ secrets.GITBOOK_PROD_API_TOKEN }}
4347
GITBOOK_ENDPOINT: https://api.gitbook.com
4448
GITBOOK_ORGANIZATION: gitbook
49+
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
4550
# GitHub Files
4651
UNFURL_GITHUB_CLIENT_ID: ${{ secrets.UNFURL_GITHUB_CLIENT_ID }}
4752
UNFURL_GITHUB_CLIENT_SECRET: ${{ secrets.UNFURL_GITHUB_CLIENT_SECRET }}

.github/workflows/release.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ jobs:
4646
uses: oven-sh/setup-bun@v2
4747
with:
4848
bun-version-file: 'package.json'
49+
- name: Setup 1Password CLI
50+
uses: ./.github/composite/setup-1password-op
51+
with:
52+
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
4953
- name: Install dependencies
5054
run: bun install --frozen-lockfile
5155
- name: Publish all integrations assets to staging
@@ -60,6 +64,7 @@ jobs:
6064
GITBOOK_TOKEN: ${{ secrets.GITBOOK_STAGING_API_TOKEN }}
6165
GITBOOK_ENDPOINT: https://api.gitbook-staging.com
6266
GITBOOK_ORGANIZATION: gitbookio
67+
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
6368
# GitHub Files
6469
UNFURL_GITHUB_CLIENT_ID: ${{ secrets.UNFURL_GITHUB_CLIENT_ID }}
6570
UNFURL_GITHUB_CLIENT_SECRET: ${{ secrets.UNFURL_GITHUB_CLIENT_SECRET }}

.github/workflows/test.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ jobs:
7070
uses: oven-sh/setup-bun@v2
7171
with:
7272
bun-version-file: 'package.json'
73+
- name: Setup 1Password CLI
74+
uses: ./.github/composite/setup-1password-op
75+
with:
76+
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
7377
- name: Install dependencies
7478
run: bun install --frozen-lockfile
7579
- name: Check
7680
run: bun run check
7781
env:
82+
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
7883
# GitHub Files
7984
UNFURL_GITHUB_CLIENT_ID: ${{ secrets.UNFURL_GITHUB_CLIENT_ID }}
8085
UNFURL_GITHUB_CLIENT_SECRET: ${{ secrets.UNFURL_GITHUB_CLIENT_SECRET }}

bun.lock

Lines changed: 112 additions & 13 deletions
Large diffs are not rendered by default.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Intercom Conversations Integration
2+
3+
This integration allows the users to ingest closed support conversations from Intercom into GitBook.
4+
5+
## Setup Instructions for development
6+
7+
1. Create an Intercom OAuth application at https://app.intercom.com/a/apps/_/developer-hub
8+
2. Set `https://<integration-domain>/v1/integrations/intercom-conversations/integration/oauth` as the redirect URL
9+
3. Get the client ID and secret
10+
It is recommended to store them in 1Password
11+
4. Set `https://<integration-domain>/v1/integrations/intercom-conversations/integration/webhook` as the webhook URL
12+
1. Go to https://app.intercom.com/a/apps/_/developer-hub/webhooks
13+
2. Create a new webhook
14+
3. Set the webhook URL to `https://<integration-domain>/v1/integrations/intercom-conversations/integration/webhook`
15+
4. Select the "Conversation closed" event type
16+
5. Save the webhook
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: intercom-conversations
2+
title: Intercom Connector
3+
icon: ./assets/icon.png
4+
description: Ingest Intercom support conversations into GitBook for auto-improvements.
5+
visibility: public
6+
script: ./src/index.ts
7+
summary: |
8+
# Overview
9+
10+
Automatically get AI-suggested change requests for your docs based on Intercom support conversations.
11+
scopes:
12+
- conversations:ingest
13+
organization: gitbook
14+
configurations:
15+
account:
16+
componentId: config
17+
secrets:
18+
CLIENT_ID: ${{ env.INTERCOM_CLIENT_ID }}
19+
CLIENT_SECRET: ${{ env.INTERCOM_CLIENT_SECRET }}
20+
target: organization
21+
envs:
22+
test:
23+
secrets:
24+
CLIENT_ID: ${{ "op://gitbook-integrations/intercomConversationsStaging/CLIENT_ID" }}
25+
CLIENT_SECRET: ${{ "op://gitbook-integrations/intercomConversationsStaging/CLIENT_SECRET" }}
26+
staging:
27+
secrets:
28+
CLIENT_ID: ${{ "op://gitbook-integrations/intercomConversationsStaging/CLIENT_ID" }}
29+
CLIENT_SECRET: ${{ "op://gitbook-integrations/intercomConversationsStaging/CLIENT_SECRET" }}
30+
dev-samy:
31+
organization: 27dLEczo4lLcYIQhRuxg
32+
secrets:
33+
CLIENT_ID: ${{ "op://gitbook-integrations/IntercomDevSamyConversations/CLIENT_ID" }}
34+
CLIENT_SECRET: ${{ "op://gitbook-integrations/IntercomDevSamyConversations/CLIENT_SECRET" }}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "@gitbook/integration-intercom-conversations",
3+
"version": "0.0.1",
4+
"private": true,
5+
"dependencies": {
6+
"@gitbook/runtime": "*",
7+
"@gitbook/api": "*",
8+
"p-map": "^7.0.3",
9+
"intercom-client": "^6.3.0"
10+
},
11+
"devDependencies": {
12+
"@gitbook/cli": "workspace:*",
13+
"@gitbook/tsconfig": "workspace:*"
14+
},
15+
"scripts": {
16+
"typecheck": "tsc --noEmit",
17+
"check": "gitbook check",
18+
"publish-integrations-staging": "gitbook publish ."
19+
}
20+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { IntercomClient } from 'intercom-client';
2+
import { IntercomRuntimeContext } from './types';
3+
import { ExposableError, getOAuthToken, OAuthConfig } from '@gitbook/runtime';
4+
5+
/**
6+
* Get the OAuth configuration for the Intercom integration.
7+
*/
8+
export function getIntercomOAuthConfig(context: IntercomRuntimeContext) {
9+
const config: OAuthConfig = {
10+
redirectURL: `${context.environment.integration.urls.publicEndpoint}/oauth`,
11+
clientId: context.environment.secrets.CLIENT_ID,
12+
clientSecret: context.environment.secrets.CLIENT_SECRET,
13+
scopes: ['conversations.read'],
14+
authorizeURL: () => 'https://app.intercom.com/oauth',
15+
accessTokenURL: () => 'https://api.intercom.io/auth/eagle/token',
16+
};
17+
18+
return config;
19+
}
20+
21+
/**
22+
* Initialize an Intercom API client for a given installation.
23+
*/
24+
export async function getIntercomClient(context: IntercomRuntimeContext) {
25+
const { installation } = context.environment;
26+
27+
if (!installation) {
28+
throw new Error('Installation not found');
29+
}
30+
31+
const { oauth_credentials } = installation.configuration;
32+
if (!oauth_credentials) {
33+
throw new Error('Intercom OAuth credentials not found');
34+
}
35+
36+
const token = await getOAuthToken(oauth_credentials, getIntercomOAuthConfig(context), context);
37+
38+
return new IntercomClient({
39+
token,
40+
});
41+
}

0 commit comments

Comments
 (0)