forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassistant.go
157 lines (122 loc) · 4.55 KB
/
assistant.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package slack
import (
"context"
"encoding/json"
"net/url"
)
// AssistantThreadSetStatusParameters are the parameters for AssistantThreadSetStatus
type AssistantThreadsSetStatusParameters struct {
ChannelID string `json:"channel_id"`
Status string `json:"status"`
ThreadTS string `json:"thread_ts"`
}
// AssistantThreadSetTitleParameters are the parameters for AssistantThreadSetTitle
type AssistantThreadsSetTitleParameters struct {
ChannelID string `json:"channel_id"`
ThreadTS string `json:"thread_ts"`
Title string `json:"title"`
}
// AssistantThreadSetSuggestedPromptsParameters are the parameters for AssistantThreadSetSuggestedPrompts
type AssistantThreadsSetSuggestedPromptsParameters struct {
Title string `json:"title"`
ChannelID string `json:"channel_id"`
ThreadTS string `json:"thread_ts"`
Prompts []AssistantThreadsPrompt `json:"prompts"`
}
// AssistantThreadPrompt is a suggested prompt for a thread
type AssistantThreadsPrompt struct {
Title string `json:"title"`
Message string `json:"message"`
}
// AssistantThreadSetSuggestedPrompts sets the suggested prompts for a thread
func (p *AssistantThreadsSetSuggestedPromptsParameters) AddPrompt(title, message string) {
p.Prompts = append(p.Prompts, AssistantThreadsPrompt{
Title: title,
Message: message,
})
}
// SetAssistantThreadsSugesstedPrompts sets the suggested prompts for a thread
// @see https://api.slack.com/methods/assistant.threads.setSuggestedPrompts
func (api *Client) SetAssistantThreadsSuggestedPrompts(params AssistantThreadsSetSuggestedPromptsParameters) (err error) {
return api.SetAssistantThreadsSuggestedPromptsContext(context.Background(), params)
}
// SetAssistantThreadSuggestedPromptsContext sets the suggested prompts for a thread with a custom context
// @see https://api.slack.com/methods/assistant.threads.setSuggestedPrompts
func (api *Client) SetAssistantThreadsSuggestedPromptsContext(ctx context.Context, params AssistantThreadsSetSuggestedPromptsParameters) (err error) {
values := url.Values{
"token": {api.token},
}
if params.ThreadTS != "" {
values.Add("thread_ts", params.ThreadTS)
}
values.Add("channel_id", params.ChannelID)
// Send Prompts as JSON
prompts, err := json.Marshal(params.Prompts)
if err != nil {
return err
}
values.Add("prompts", string(prompts))
response := struct {
SlackResponse
}{}
err = api.postMethod(ctx, "assistant.threads.setSuggestedPrompts", values, &response)
if err != nil {
return
}
return response.Err()
}
// SetAssistantThreadStatus sets the status of a thread
// @see https://api.slack.com/methods/assistant.threads.setStatus
func (api *Client) SetAssistantThreadsStatus(params AssistantThreadsSetStatusParameters) (err error) {
return api.SetAssistantThreadsStatusContext(context.Background(), params)
}
// SetAssistantThreadStatusContext sets the status of a thread with a custom context
// @see https://api.slack.com/methods/assistant.threads.setStatus
func (api *Client) SetAssistantThreadsStatusContext(ctx context.Context, params AssistantThreadsSetStatusParameters) (err error) {
values := url.Values{
"token": {api.token},
}
if params.ThreadTS != "" {
values.Add("thread_ts", params.ThreadTS)
}
values.Add("channel_id", params.ChannelID)
// Always send the status parameter, if empty, it will clear any existing status
values.Add("status", params.Status)
response := struct {
SlackResponse
}{}
err = api.postMethod(ctx, "assistant.threads.setStatus", values, &response)
if err != nil {
return
}
return response.Err()
}
// SetAssistantThreadsTitle sets the title of a thread
// @see https://api.slack.com/methods/assistant.threads.setTitle
func (api *Client) SetAssistantThreadsTitle(params AssistantThreadsSetTitleParameters) (err error) {
return api.SetAssistantThreadsTitleContext(context.Background(), params)
}
// SetAssistantThreadsTitleContext sets the title of a thread with a custom context
// @see https://api.slack.com/methods/assistant.threads.setTitle
func (api *Client) SetAssistantThreadsTitleContext(ctx context.Context, params AssistantThreadsSetTitleParameters) (err error) {
values := url.Values{
"token": {api.token},
}
if params.ChannelID != "" {
values.Add("channel_id", params.ChannelID)
}
if params.ThreadTS != "" {
values.Add("thread_ts", params.ThreadTS)
}
if params.Title != "" {
values.Add("title", params.Title)
}
response := struct {
SlackResponse
}{}
err = api.postMethod(ctx, "assistant.threads.setTitle", values, &response)
if err != nil {
return
}
return response.Err()
}