Skip to content
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

Enhance: Add support to pull slack bot token #451

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions oauth2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type oauthInfo struct {
Integration string `json:"integration"`
Token string `json:"token"`
Scope []string `json:"scope"`
UserScope []string `json:"userScope"`
OptionalScope []string `json:"optionalScope"`
}

Expand Down Expand Up @@ -227,6 +228,9 @@ func mainErr() (err error) {
if len(in.OAuthInfo.Scope) != 0 {
q.Set("scope", strings.Join(in.OAuthInfo.Scope, " "))
}
if len(in.OAuthInfo.UserScope) != 0 {
q.Set("user_scope", strings.Join(in.OAuthInfo.UserScope, " "))
}
if len(in.OAuthInfo.OptionalScope) != 0 {
q.Set("optional_scope", strings.Join(in.OAuthInfo.OptionalScope, " "))
}
Expand Down
32 changes: 32 additions & 0 deletions slack/credential/bot.gpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Name: Slack OAuth Bot Credential
Share Credential: slack-bot-cred as slack.bot.write
Type: credential

---
Name: slack-bot-cred
Tools: ../../oauth2

#!sys.call ../../oauth2

{
"oauthInfo": {
"integration": "slack",
"token": "SLACK_TOKEN",
"scope": [
"chat:write",
"im:write",
"users:read"
]
},
"promptInfo": {
"fields" : [
{
"name": "Slack API Key",
"description": "A Bot token for your Slack account.",
"sensitive": true,
"env": "SLACK_TOKEN"
}
],
"message": "Enter your Slack User or Bot OAuth Token."
}
}
4 changes: 2 additions & 2 deletions slack/credential/tool.gpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Tools: ../../oauth2
"oauthInfo": {
"integration": "slack",
"token": "SLACK_TOKEN",
"scope": [
"userScope": [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am changing this so that it is consistent with slack.

"channels:history",
"groups:history",
"im:history",
Expand All @@ -34,7 +34,7 @@ Tools: ../../oauth2
"fields" : [
{
"name": "Slack API Key",
"description": "An OAuth User or Bot token for your GitHub account.",
"description": "An OAuth User or Bot token for your Slack account.",
"sensitive": true,
"env": "SLACK_TOKEN"
}
Expand Down
12 changes: 11 additions & 1 deletion slack/tool.gpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Name: Slack
Description: Tools for interacting with Slack
Metadata: bundle: true
Share Tools: List Channels, Search Channels, Get Channel History, Get Channel History by Time, Get Thread History From Link, Get Thread History, Search Messages, Send Message, Send Message in Thread, List Users, Search Users, Send DM, Send DM in Thread, Get Message Link, Get DM History, Get DM Thread History
Share Tools: List Channels, Search Channels, Get Channel History, Get Channel History by Time, Get Thread History From Link, Get Thread History, Search Messages, Send Message, Send Message in Thread, List Users, Search Users, Send DM, Send DM in Thread, Get Message Link, Get DM History, Get DM Thread History, Send Direct Message As Bot

---
Name: List Channels
Expand Down Expand Up @@ -184,6 +184,16 @@ Param: limit: the number of messages to return

#!/usr/bin/env node ${GPTSCRIPT_TOOL_DIR}/index.js getDMThreadHistory

---
Name: Send Direct Message As Bot
Description: Send a direct message as a bot or an app in the Slack workspace
Share Context: Slack Context
Credential: ./credential/bot.gpt
Share Tools: List Users, Search Users
Param: userids: comma-separated list of user IDs to send the message to for a group message (example: USER1ID,USER2ID), or just one ID for an individual message
Param: text: the text to send

#!/usr/bin/env node ${GPTSCRIPT_TOOL_DIR}/index.js sendDM
---
Name: User Context
Description: Get information about the logged in user.
Expand Down
Loading