-
Notifications
You must be signed in to change notification settings - Fork 27
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
Slack integration with Obot #1991
base: main
Are you sure you want to change the base?
Conversation
7ec16f7
to
7cf2086
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more comments to come, just wanted to get these ones out there
pkg/api/handlers/projects.go
Outdated
@@ -673,6 +673,22 @@ func (h *ProjectsHandler) authenticate(req api.Context, local bool) (err error) | |||
return err | |||
} | |||
|
|||
var oauthApps v1.OAuthAppList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this block of code do?
ui/user/vite.config.ts
Outdated
@@ -8,7 +8,8 @@ export default defineConfig({ | |||
'/api': 'http://localhost:8080', | |||
'/admin': 'http://localhost:8080', | |||
'/oauth2': 'http://localhost:8080' | |||
} | |||
}, | |||
allowedHosts: ['04ac-70-184-112-91.ngrok-free.app'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i assume this is a short term thing?
@@ -247,7 +247,7 @@ func OAuthAppEnv(ctx context.Context, db kclient.Client, oauthAppNames []string, | |||
|
|||
for _, integration := range slices.Sorted(maps.Keys(activeIntegrations)) { | |||
app := activeIntegrations[integration] | |||
integrationEnv := strings.ReplaceAll(strings.ToUpper(app.Spec.Manifest.Alias), "-", "_") | |||
integrationEnv := strings.ReplaceAll(strings.ToUpper(string(app.Spec.Manifest.Type)), "-", "_") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
pkg/api/handlers/slack.go
Outdated
return err | ||
} | ||
|
||
scopes := []string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we let the obot author define scopes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be removed. We don't really need scopes here, just need to have user go to the oauth flow and install the app to their workspace.
return &SlackEventHandler{invoker: invoker, gptscript: gptscript} | ||
} | ||
|
||
type SlackEvent struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in their docs, they make a big deal about verify thing token
https://api.slack.com/apis/events-api
The shared-private callback token that authenticates this callback to the application as having come from Slack. Match this against what you were given when the subscription was created. If it does not match, do not process the event and discard it. Example: JhjZd2rVax7ZwH7jRYyWjbDl
Should we be checking that as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is deprecated. Using the sign secret is in favor of.
This deprecated Verification Token can still be used to verify that requests come from Slack, but we strongly recommend using the above, more secure, signing secret instead.
pkg/api/router/router.go
Outdated
@@ -123,6 +124,14 @@ func Router(services *services.Services) (http.Handler, error) { | |||
mux.HandleFunc("GET /api/assistants/{assistant_id}/projects/{project_id}/env", assistants.GetEnv) | |||
mux.HandleFunc("PUT /api/assistants/{assistant_id}/projects/{project_id}/env", assistants.SetEnv) | |||
|
|||
// Project Slack integration | |||
mux.HandleFunc("GET /api/assistants/{assistant_id}/projects/{project_id}/slack/authorize", projects.SlackAuthorize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where does this get used? do i drop it into slack somewher?
pkg/api/handlers/slack.go
Outdated
app.Spec.Manifest.ClientID, | ||
url.QueryEscape(strings.Join(scopes, ",")), | ||
url.QueryEscape(strings.Join(userScopes, ",")), | ||
url.QueryEscape(fmt.Sprintf("https://%s/api/slack/oauth/callback/%s", req.Host, app.Name))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to use something other than req.host.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
theres an env var
Signed-off-by: Daishan Peng <[email protected]>
Signed-off-by: Daishan Peng <[email protected]>
This is the exact workflow/UX user will have to follow if they want to configure a custom app in their workspace and being able to delegate task to the task from every message that mentions the bot:
Use
/api/assistants/{assistant_id}/projects/{project_id}/slack/configure
to configure a custom oauth app for their obot and get a id. They need to create a slack app, configure the callback url to /api/slack/oauth/callback/{id}, set event redirect url to/api/slack/event
and all the right scopes.Use
/api/assistants/{assistant_id}/projects/{project_id}/slack/authorize
to authorize. This will bind Obot with the workspace they have signed in. We will save the team id and name into the obot so that UI can create slack trigger based on the information. Slack trigger is a 1 to 1 mapping bewteen (workspace_id and app_id) to task.Use
/api/slack-triggers
to create trigger to trigger task from your slack workspace.The UX on the end user would be: