feat: send text messages
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a3136305d3
commit
ff6bf16048
2 files changed
+141
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package signalbot
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type sendRequest struct {
|
||||
Number string `json:"number"`
|
||||
Recipients []string `json:"recipients"`
|
||||
Message string `json:"message"`
|
||||
TextMode string `json:"text_mode"`
|
||||
}
|
||||
|
||||
// Send sends a plain-text message. to is a group id ("group.<base64>", see
|
||||
// Groups), a phone number in E.164 format, or an ACI UUID. The text is sent
|
||||
// as is: markdown is not interpreted. Send does not retry.
|
||||
func (c *Client) Send(ctx context.Context, to, text string) error {
|
||||
if strings.TrimSpace(text) == "" {
|
||||
return ErrEmptyText
|
||||
}
|
||||
acct, err := c.account(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return c.do(ctx, http.MethodPost, "/v2/send", sendRequest{
|
||||
Number: acct.id(),
|
||||
Recipients: []string{to},
|
||||
Message: text,
|
||||
TextMode: "normal",
|
||||
}, nil)
|
||||
}
|
||||
Reference in new issue
Block a user