Allow slack bots to initiate conversations
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
@@ -41,6 +41,7 @@ type Agent struct {
|
||||
|
||||
mcpActions types.Actions
|
||||
|
||||
subscriberMutex sync.Mutex
|
||||
newMessagesSubscribers []func(openai.ChatCompletionMessage)
|
||||
}
|
||||
|
||||
@@ -118,7 +119,10 @@ func (a *Agent) startNewConversationsConsumer() {
|
||||
return
|
||||
|
||||
case msg := <-a.newConversations:
|
||||
for _, s := range a.newMessagesSubscribers {
|
||||
a.subscriberMutex.Lock()
|
||||
subs := a.newMessagesSubscribers
|
||||
a.subscriberMutex.Unlock()
|
||||
for _, s := range subs {
|
||||
s(msg)
|
||||
}
|
||||
}
|
||||
@@ -126,6 +130,12 @@ func (a *Agent) startNewConversationsConsumer() {
|
||||
}()
|
||||
}
|
||||
|
||||
func (a *Agent) AddSubscriber(f func(openai.ChatCompletionMessage)) {
|
||||
a.subscriberMutex.Lock()
|
||||
defer a.subscriberMutex.Unlock()
|
||||
a.newMessagesSubscribers = append(a.newMessagesSubscribers, f)
|
||||
}
|
||||
|
||||
// StopAction stops the current action
|
||||
// if any. Can be called before adding a new job.
|
||||
func (a *Agent) StopAction() {
|
||||
|
||||
Reference in New Issue
Block a user