Joe supports reacting to messages with Emojis if the chat adapter has this feature. For instance in Slack your bot could add a 🤖 emoji to a message to indicate to the user, that the bot has seen it. Another use case of reactions is that you may want to trigger an action if the user attaches an emoji to a message.
Currently the following chat adapters support reactions:
The following example shows how you can use reactions in your message handlers:
package main
import (
"fmt"
"github.com/go-joe/joe"
"github.com/go-joe/joe/reactions"
)
func main() {
b := joe.New("example-bot")
b.Respond("hello", MyHandler)
b.Brain.RegisterHandler(ReceiveReaction)
err := b.Run()
if err != nil {
b.Logger.Fatal(err.Error())
}
}
func MyHandler(msg joe.Message) error {
err := msg.React(reactions.Thumbsup)
if err != nil {
msg.Respond("Sorry but there was an issue attaching a reaction: %v", err)
}
// custom reactions are also possible
_ = msg.React(reactions.Reaction{Shortcode: "foo"})
return err
}
func ReceiveReaction(evt reactions.Event) error {
fmt.Printf("Received event: %+v", evt)
return nil
}
If you try to react to a message, when your chat adapter does not support this
feature, the Message.React(…)
function will return the joe.ErrNotImplemented
sentinel error.