Skip to content

Commit eb2a86d

Browse files
committed
upgrading to use API 4.0
1 parent c8984d4 commit eb2a86d

9 files changed

+54
-54
lines changed

.env-sample

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
SLACK_API_KEY=fooo-abc123
22
SLACK_SLASH_COMMAND_TOKEN=abc123
33
LOOKER_URL=https://me.looker.com
4-
LOOKER_API_BASE_URL=https://me.looker.com:19999/api/3.0
5-
LOOKER_API_3_CLIENT_ID=abcdefghjkl
6-
LOOKER_API_3_CLIENT_SECRET=abcdefghjkl
7-
LOOKER_CUSTOM_COMMAND_SPACE_ID=13
4+
LOOKER_API_BASE_URL=https://me.looker.com:19999/api/4.0
5+
LOOKER_API_CLIENT_ID=abcdefghjkl
6+
LOOKER_API_CLIENT_SECRET=abcdefghjkl
7+
LOOKER_CUSTOM_COMMAND_FOLDER_ID=13
88
SLACKBOT_S3_BUCKET=my-bucket
99
SLACKBOT_S3_BUCKET_REGION=us-east-1
1010
AWS_ACCESS_KEY_ID=ABCDEFGHJKL

README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ The bot is configured entirely via environment variables. You'll want to set up
7272

7373
- `LOOKER_URL` (required) – The web url of your Looker instance.
7474

75-
- `LOOKER_API_BASE_URL` (required) – The API 3.0 endpoint of your Looker instance. In most cases, this will be the web url followed by `:19999/api/3.0` (replace `19999` with your `core_port` if it is different).
75+
- `LOOKER_API_BASE_URL` (required) – The API endpoint of your Looker instance. In most cases, this will be the web url followed by `:19999/api/4.0` (replace `19999` with your `core_port` if it is different).
7676

77-
- `LOOKER_API_3_CLIENT_ID` (required) – The API 3.0 client ID for the user you want the bot to run as. This requires creating an API 3.0 user or an API 3.0 key for an existing user in Looker.
77+
- `LOOKER_API_CLIENT_ID` (required) – The API client ID for the user you want the bot to run as. This requires creating an API user or an API key for an existing user in Looker.
7878

79-
- `LOOKER_API_3_CLIENT_SECRET` (required) – The API 3.0 client secret for the user you want the bot to run as. This requires creating an API 3.0 user or an API 3.0 key for an existing user in Looker.
79+
- `LOOKER_API_CLIENT_SECRET` (required) – The API client secret for the user you want the bot to run as. This requires creating an API user or an API key for an existing user in Looker.
8080

81-
- `LOOKER_CUSTOM_COMMAND_SPACE_ID` (optional) – The ID of a Space that you would like the bot to use to define custom commands. [Read about using custom commands in the Looker Help Center](https://help.looker.com/hc/en-us/articles/360023685434-Using-Lookerbot-for-Slack).
81+
- `LOOKER_CUSTOM_COMMAND_FOLDER_ID` (optional) – The ID of a Folder that you would like the bot to use to define custom commands. [Read about using custom commands in the Looker Help Center](https://help.looker.com/hc/en-us/articles/360023685434-Using-Lookerbot-for-Slack).
8282

8383
- `LOOKER_WEBHOOK_TOKEN` (optional) – The webhook validation token found in Looker's admin panel. This is only required if you're using the bot to send scheduled webhooks.
8484

@@ -145,19 +145,19 @@ If you would like the bot to connect to multiple instances of Looker, then you c
145145
The JSON objects should have the following keys:
146146

147147
- `url` should be the web url of the instance
148-
- `apiBaseUrl` should be the API 3.0 endpoint
149-
- `clientID` should be the API 3.0 client ID for the user you want the bot to run as
150-
- `clientSecret` should be the secret for that API 3.0 key
151-
- `customCommandSpaceId` is an optional parameter, representing a Space that you would like the bot to use to define custom commands.
148+
- `apiBaseUrl` should be the API endpoint
149+
- `clientID` should be the API client ID for the user you want the bot to run as
150+
- `clientSecret` should be the secret for that API key
151+
- `customCommandFolderId` is an optional parameter, representing a Folder that you would like the bot to use to define custom commands.
152152
- `webhookToken` is an optional parameter. It's the webhook validation token found in Looker's admin panel. This is only required if you're using the bot to send scheduled webhooks.
153153

154154
Here's an example JSON that connects to two Looker instances:
155155

156156
```json
157-
[{"url": "https://me.looker.com", "apiBaseUrl": "https://me.looker.com:19999/api/3.0", "clientId": "abcdefghjkl", "clientSecret": "abcdefghjkl"},{"url": "https://me-staging.looker.com", "apiBaseUrl": "https://me-staging.looker.com:19999/api/3.0", "clientId": "abcdefghjkl", "clientSecret": "abcdefghjkl"}]
157+
[{"url": "https://me.looker.com", "apiBaseUrl": "https://me.looker.com:19999/api/4.0", "clientId": "abcdefghjkl", "clientSecret": "abcdefghjkl"},{"url": "https://me-staging.looker.com", "apiBaseUrl": "https://me-staging.looker.com:19999/api/4.0", "clientId": "abcdefghjkl", "clientSecret": "abcdefghjkl"}]
158158
```
159159

160-
The `LOOKER_URL`, `LOOKER_API_BASE_URL`, `LOOKER_API_3_CLIENT_ID`, `LOOKER_API_3_CLIENT_SECRET`, `LOOKER_WEBHOOK_TOKEN`, and `LOOKER_CUSTOM_COMMAND_SPACE_ID` variables are ignored when `LOOKERS` is set.
160+
The `LOOKER_URL`, `LOOKER_API_BASE_URL`, `LOOKER_API_CLIENT_ID`, `LOOKER_API_CLIENT_SECRET`, `LOOKER_WEBHOOK_TOKEN`, and `LOOKER_CUSTOM_COMMAND_FOLDER_ID` variables are ignored when `LOOKERS` is set.
161161

162162
##### Running the Server
163163

app.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
"value": "https://mycompany.looker.com"
1616
},
1717
"LOOKER_API_BASE_URL": {
18-
"description": "The API 3.0 endpoint of your Looker instance.",
18+
"description": "The API 4.0 endpoint of your Looker instance.",
1919
"required": true,
20-
"value": "https://mycompany.looker.com:19999/api/3.0"
20+
"value": "https://mycompany.looker.com:19999/api/4.0"
2121
},
22-
"LOOKER_API_3_CLIENT_ID": {
23-
"description": "The API 3.0 client ID for the user you want the bot to run as.",
22+
"LOOKER_API_CLIENT_ID": {
23+
"description": "The API client ID for the user you want the bot to run as.",
2424
"required": true
2525
},
26-
"LOOKER_API_3_CLIENT_SECRET": {
27-
"description": "The API 3.0 client secret for the user you want the bot to run as.",
26+
"LOOKER_API_CLIENT_SECRET": {
27+
"description": "The API client secret for the user you want the bot to run as.",
2828
"required": true
2929
},
30-
"LOOKER_CUSTOM_COMMAND_SPACE_ID": {
31-
"description": "The ID of a Space that you would like the bot to use to define custom commands.",
30+
"LOOKER_CUSTOM_COMMAND_FOLDER_ID": {
31+
"description": "The ID of a Folder that you would like the bot to use to define custom commands.",
3232
"required": false
3333
},
3434
"SLACK_SLASH_COMMAND_TOKEN": {

src/commands/help_command.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ export class HelpCommand extends Command {
4848
title: "Built-in Commands",
4949
})
5050

51-
const spaces = Looker.all.filter((l) => l.customCommandSpaceId).map((l) => {
52-
return `<${l.url}/spaces/${l.customCommandSpaceId}|this space>`
51+
const folders = Looker.all.filter((l) => l.customCommandFolderId).map((l) => {
52+
return `<${l.url}/folders/${l.customCommandFolderId}|this folder>`
5353
}).join(" or ")
5454

55-
if (spaces) {
55+
if (folders) {
5656
helpAttachments.push({
5757
mrkdwn_in: ["text"],
58-
text: `\n_To add your own commands, add a dashboard to ${spaces}._`,
58+
text: `\n_To add your own commands, add a dashboard to ${folders}._`,
5959
})
6060
}
6161

src/looker.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IDashboard, ISpace } from "./looker_api_types"
1+
import { IDashboard, IFolder } from "./looker_api_types"
22
import { LookerAPIClient } from "./looker_client"
33

44
export interface ICustomCommand {
@@ -15,7 +15,7 @@ interface ILookerOptions {
1515
apiBaseUrl: string
1616
clientId: string
1717
clientSecret: string
18-
customCommandSpaceId: string
18+
customCommandFolderId: string
1919
url: string
2020
webhookToken: string
2121
}
@@ -37,24 +37,24 @@ export class Looker {
3737
(console.log("Using Looker information specified in individual environment variables."),
3838
[{
3939
apiBaseUrl: process.env.LOOKER_API_BASE_URL,
40-
clientId: process.env.LOOKER_API_3_CLIENT_ID,
41-
clientSecret: process.env.LOOKER_API_3_CLIENT_SECRET,
42-
customCommandSpaceId: process.env.LOOKER_CUSTOM_COMMAND_SPACE_ID,
40+
clientId: process.env.LOOKER_API_CLIENT_ID,
41+
clientSecret: process.env.LOOKER_API_CLIENT_SECRET,
42+
customCommandFolderId: process.env.LOOKER_CUSTOM_COMMAND_FOLDER_ID,
4343
url: process.env.LOOKER_URL,
4444
webhookToken: process.env.LOOKER_WEBHOOK_TOKEN,
4545
}])
4646
return this.all = configs.map((config) => new Looker(config))
4747
}
4848

4949
public url: string
50-
public customCommandSpaceId: string
50+
public customCommandFolderId: string
5151
public webhookToken: string
5252
public client: LookerAPIClient
5353

5454
constructor(options: ILookerOptions) {
5555

5656
this.url = options.url
57-
this.customCommandSpaceId = options.customCommandSpaceId
57+
this.customCommandFolderId = options.customCommandFolderId
5858
this.webhookToken = options.webhookToken
5959

6060
this.client = new LookerAPIClient({
@@ -68,25 +68,25 @@ export class Looker {
6868
}
6969

7070
public refreshCommands() {
71-
if (!this.customCommandSpaceId) {
71+
if (!this.customCommandFolderId) {
7272
console.log(`No commands specified for ${this.url}...`)
7373
return
7474
}
7575
console.log(`Refreshing custom commands for ${this.url}...`)
7676

77-
this.client.get(`spaces/${this.customCommandSpaceId}`, (space: ISpace) => {
78-
this.addCommandsForSpace(space, "Shortcuts")
79-
this.client.get(`spaces/${this.customCommandSpaceId}/children`, (children: ISpace[]) => {
77+
this.client.get(`folders/${this.customCommandFolderId}`, (folder: IFolder) => {
78+
this.addCommandsForFolder(folder, "Shortcuts")
79+
this.client.get(`folders/${this.customCommandFolderId}/children`, (children: IFolder[]) => {
8080
children.map((child) =>
81-
this.addCommandsForSpace(child, child.name))
81+
this.addCommandsForFolder(child, child.name))
8282
},
8383
console.log)
8484
},
8585
console.log)
8686
}
8787

88-
private addCommandsForSpace(space: ISpace, category: string) {
89-
space.dashboards.forEach((partialDashboard) =>
88+
private addCommandsForFolder(folder: IFolder, category: string) {
89+
folder.dashboards.forEach((partialDashboard) =>
9090
this.client.get(`dashboards/${partialDashboard.id}`, (dashboard: IDashboard) => {
9191

9292
const command: ICustomCommand = {

src/looker_api_types.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
export interface ISpace {
1+
export interface IFolder {
22
id: string
33
name: string
44
dashboards: IDashboard[]
55
}
66

77
export interface IDashboard {
8-
id: string | number
8+
id: string
99
description: string
1010
title: string
1111
filters?: IDashboardFilter[]
@@ -18,11 +18,11 @@ export interface IDashboardElement {
1818
look?: ILook
1919
query?: IQuery
2020
listen?: {[key: string]: string} // deprecated
21-
result_maker_id?: number
21+
result_maker_id?: string
2222
result_maker?: {
23-
id: number,
24-
query_id?: number,
25-
merge_result_id?: number,
23+
id: string,
24+
query_id?: string,
25+
merge_result_id?: string,
2626
filterables?: IDashboardElementResultMakerFilterable[],
2727
}
2828
}
@@ -41,7 +41,7 @@ export interface IDashboardFilter {
4141
}
4242

4343
export interface ILook {
44-
id: number
44+
id: string
4545
query: IQuery
4646
}
4747

@@ -50,7 +50,7 @@ export interface IQueryFilters {
5050
}
5151

5252
export interface IQuery {
53-
id: number
53+
id: string
5454
slug: string
5555
share_url: string
5656
vis_config: {

src/repliers/look_finder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class LookFinder extends QueryRunner {
2121
attachments: shortResults.map((v: any) => {
2222
const look = v.value
2323
return {
24-
text: `in ${look.space.name}`,
24+
text: `in ${look.folder.name}`,
2525
title: look.title,
2626
title_link: `${this.replyContext.looker.url}${look.short_url}`,
2727
}
@@ -35,7 +35,7 @@ export class LookFinder extends QueryRunner {
3535

3636
private async matchLooks() {
3737
const looks = await this.replyContext.looker.client.getAsync(
38-
"looks?fields=id,title,short_url,space(name,id)",
38+
"looks?fields=id,title,short_url,folder(name,id)",
3939
this.replyContext,
4040
)
4141

src/repliers/look_query_runner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export class LookQueryRunner extends QueryRunner {
88

99
constructor(
1010
replyContext: ReplyContext,
11-
private lookId: number | string,
12-
private filterInfo?: {queryId: number, url: string},
11+
private lookId: string,
12+
private filterInfo?: {queryId: string, url: string},
1313
) {
1414
super(replyContext)
1515
this.lookId = lookId

src/repliers/query_runner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { SlackTableFormatter } from "./slack_table_formatter"
99
export class QueryRunner extends FancyReplier {
1010

1111
protected querySlug?: string
12-
protected queryId?: number
12+
protected queryId?: string
1313

14-
constructor(replyContext: ReplyContext, queryParam: {slug?: string, id?: number} = {}) {
14+
constructor(replyContext: ReplyContext, queryParam: {slug?: string, id?: string} = {}) {
1515
super(replyContext)
1616
this.querySlug = queryParam.slug
1717
this.queryId = queryParam.id

0 commit comments

Comments
 (0)