Allow slack bots to initiate conversations

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto
2025-03-25 22:58:59 +01:00
parent fa12dba7c2
commit fb20bbe5bf
2 changed files with 31 additions and 6 deletions

View File

@@ -642,6 +642,11 @@ func (t *Slack) handleMention(
}
func (t *Slack) Start(a *agent.Agent) {
postMessageParams := slack.PostMessageParameters{
LinkNames: 1,
Markdown: true,
}
api := slack.New(
t.botToken,
// slack.OptionDebug(true),
@@ -649,13 +654,23 @@ func (t *Slack) Start(a *agent.Agent) {
slack.OptionAppLevelToken(t.appToken),
)
t.apiClient = api
postMessageParams := slack.PostMessageParameters{
LinkNames: 1,
Markdown: true,
if t.channelID != "" {
// handle new conversations
a.AddSubscriber(func(ccm openai.ChatCompletionMessage) {
_, _, err := api.PostMessage(t.channelID,
slack.MsgOptionLinkNames(true),
slack.MsgOptionEnableLinkUnfurl(),
slack.MsgOptionText(ccm.Content, true),
slack.MsgOptionPostMessageParameters(postMessageParams),
)
if err != nil {
xlog.Error(fmt.Sprintf("Error posting message: %v", err))
}
})
}
t.apiClient = api
client := socketmode.New(
api,
//socketmode.OptionDebug(true),