-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
40 lines (36 loc) · 1.25 KB
/
main.ts
File metadata and controls
40 lines (36 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Quickstart: fetch last 5 unread Gmail messages via Scalekit.
* Run: npx tsx javascript/frameworks/quickstart/main.ts
*/
import { ScalekitClient } from '@scalekit-sdk/node'
import { ConnectorStatus } from '@scalekit-sdk/node/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.js'
import 'dotenv/config'
const scalekit = new ScalekitClient(
process.env.SCALEKIT_ENVIRONMENT_URL!,
process.env.SCALEKIT_CLIENT_ID!,
process.env.SCALEKIT_CLIENT_SECRET!,
)
const actions = scalekit.actions
const response = await actions.getOrCreateConnectedAccount({
connectionName: 'gmail',
identifier: 'user_123',
})
const connectedAccount = response.connectedAccount
console.log('Connected account:', connectedAccount?.id, '| status:', connectedAccount?.status)
if (connectedAccount?.status !== ConnectorStatus.ACTIVE) {
const linkResponse = await actions.getAuthorizationLink({
connectionName: 'gmail',
identifier: 'user_123',
})
console.log('Authorize Gmail:', linkResponse.link)
process.exit(0)
}
const toolResponse = await actions.executeTool({
toolName: 'gmail_fetch_mails',
connectedAccountId: connectedAccount?.id,
toolInput: {
query: 'is:unread',
max_results: 5,
},
})
console.log('Recent emails:', toolResponse.data)