docs: README, compose example, integration test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vincent BourdonandClaude Opus 5.5 committed 2026-11-20 15:45:23 +01:00
1 parent 15874f7ecb
commit 45f88378a6
4 files changed
+236

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
// Command example announces itself in a group, then answers every incoming
// text message with an echo.
//
// SIGNAL_API_URL=http://localhost:8080 SIGNAL_GROUP_ID=group.… go run ./examples
package main
import (
"context"
"errors"
"log"
"os"
"os/signal"
"git.siteop.biz/vincentb99/signalbot"
)
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
client, err := signalbot.New(os.Getenv("SIGNAL_API_URL"))
if err != nil {
log.Fatal(err)
}
if group := os.Getenv("SIGNAL_GROUP_ID"); group != "" {
if err := client.Send(ctx, group, "example bot started"); err != nil {
log.Printf("announce: %v", err)
}
}
// Keep Listen running even if you only publish: it also processes the
// retry receipts that keep group members able to decrypt your messages.
err = client.Listen(ctx, func(ctx context.Context, m signalbot.Message) {
if err := m.Reply(ctx, "echo: "+m.Text); err != nil {
log.Printf("reply: %v", err)
}
})
if err != nil && !errors.Is(err, context.Canceled) {
log.Fatal(err)
}
}