Skip to content

Commit

Permalink
Enhance: Add support to pull slack bot token (#451)
Browse files Browse the repository at this point in the history
Signed-off-by: Daishan Peng <[email protected]>
  • Loading branch information
StrongMonkey authored Feb 20, 2025
1 parent 0637bb6 commit ba9760a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
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": [
"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

0 comments on commit ba9760a

Please sign in to comment.