Corrected the script

This commit is contained in:
2025-06-17 00:06:45 +02:00
committed by GitHub
parent 6299e4e01a
commit 99c016dba9

View File

@@ -51,11 +51,11 @@ type Key struct {
func connect(param Parameters) (*whatsmeow.Client, error) { func connect(param Parameters) (*whatsmeow.Client, error) {
dbLog := waLog.Stdout("Database", "ERROR", true) dbLog := waLog.Stdout("Database", "ERROR", true)
container, err := sqlstore.New("sqlite3", "file:" + param.WhatsappSessionFile + "?_foreign_keys=on", dbLog) container, err := sqlstore.New(context.Background(), "sqlite3", "file:" + param.WhatsappSessionFile + "?_foreign_keys=on", dbLog)
if err != nil { if err != nil {
return nil, err return nil, err
} }
deviceStore, err := container.GetFirstDevice() deviceStore, err := container.GetFirstDevice(context.Background())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -94,14 +94,23 @@ func sendMessage(client *whatsmeow.Client, group string, message string, url str
return fmt.Errorf("Incorrect group identifier '%s': %v", group, err) return fmt.Errorf("Incorrect group identifier '%s': %v", group, err)
} }
msg := &waProto.Message{ExtendedTextMessage: &waProto.ExtendedTextMessage{ // msg := &waProto.Message{ExtendedTextMessage: &waProto.ExtendedTextMessage{
Text: proto.String(message), // Text: proto.String(message),
Title: proto.String(title), // Title: proto.String(title),
Description: proto.String(title), // Description: proto.String(title),
CanonicalURL: proto.String(url), // CanonicalUrl: proto.String(url),
MatchedText: proto.String(url), // MatchedText: proto.String(url),
JPEGThumbnail: thumbnail, // JPEGThumbnail: thumbnail,
}} // }}
msg := &waProto.Message{
ExtendedTextMessage: &waProto.ExtendedTextMessage{
Text: proto.String(fmt.Sprintf("%s\n%s\n%s", title, message, url)),
Title: proto.String(title),
Description: proto.String(message),
// PreviewType: proto.Uint32(0), // 0 pour un lien standard
JPEGThumbnail: thumbnail,
},
}
ts, err := client.SendMessage(context.Background(), jid, msg) ts, err := client.SendMessage(context.Background(), jid, msg)
if err != nil { if err != nil {
return fmt.Errorf("Error sending message with title '%s': %v", title, err) return fmt.Errorf("Error sending message with title '%s': %v", title, err)