Skip to content

Commit 5568953

Browse files
authored
Chore: add ability to get user's current email address (#510)
Signed-off-by: Daishan Peng <[email protected]>
1 parent b8d4c42 commit 5568953

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

index.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ system:
121121
reference: ./docker
122122
tasks-workflow:
123123
reference: ./tasks-workflow
124-
safe-search:
125-
reference: ./search/tavily/safesearch.gpt
126124

127125
modelProviders:
128126
openai-model-provider:

outlook/mail/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ func main() {
7474
fmt.Printf("failed to move message: %v\n", err)
7575
os.Exit(1)
7676
}
77+
case "getMyEmailAddress":
78+
if err := commands.GetMyEmailAddress(context.Background()); err != nil {
79+
fmt.Printf("failed to get my email address: %v\n", err)
80+
os.Exit(1)
81+
}
7782
default:
7883
fmt.Printf("Unknown command: %s\n", command)
7984
os.Exit(1)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package commands
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/gptscript-ai/tools/outlook/mail/pkg/client"
8+
"github.com/gptscript-ai/tools/outlook/mail/pkg/global"
9+
"github.com/gptscript-ai/tools/outlook/mail/pkg/graph"
10+
)
11+
12+
func GetMyEmailAddress(ctx context.Context) error {
13+
c, err := client.NewClient(global.AllScopes)
14+
if err != nil {
15+
return fmt.Errorf("failed to create client: %w", err)
16+
}
17+
18+
user, err := graph.GetMe(ctx, c)
19+
if err != nil {
20+
return fmt.Errorf("failed to get me: %w", err)
21+
}
22+
23+
email := user.GetMail()
24+
if email == nil {
25+
return fmt.Errorf("failed to get email address")
26+
}
27+
28+
fmt.Printf("Current user email address is %s\n", *email)
29+
return nil
30+
}

outlook/mail/pkg/graph/mail.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,11 @@ func MoveMessage(ctx context.Context, client *msgraphsdkgo.GraphServiceClient, m
319319

320320
return message, nil
321321
}
322+
323+
func GetMe(ctx context.Context, client *msgraphsdkgo.GraphServiceClient) (models.Userable, error) {
324+
user, err := client.Me().Get(ctx, nil)
325+
if err != nil {
326+
return nil, fmt.Errorf("failed to get me: %w", err)
327+
}
328+
return user, nil
329+
}

outlook/mail/tool.gpt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Name: Outlook Mail
33
Description: Tools for interacting with Microsoft Outlook Mail.
44
Metadata: bundle: true
5-
Share Tools: List Mail Folders, List Messages, Get Message Details, Search Messages, Create Draft, Send Draft, Delete Message, Move Message
5+
Share Tools: List Mail Folders, List Messages, Get Message Details, Search Messages, Create Draft, Send Draft, Delete Message, Move Message, Current Email
66

77
---
88
Name: List Mail Folders
@@ -103,6 +103,14 @@ Param: destination_folder_id: The ID of the folder to move the message into.
103103

104104
#!${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool moveMessage
105105

106+
---
107+
Name: Current Email
108+
Description: Get the email address of the currently authenticated user.
109+
Share Context: Outlook Mail Context
110+
Credential: ./credential
111+
112+
#!${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool getMyEmailAddress
113+
106114
---
107115
Name: Outlook Mail Context
108116
Type: context

0 commit comments

Comments
 (0)