MCPcopy
hub / github.com/42wim/matterbridge / Send

Method Send

bridge/whatsappmulti/whatsapp.go:351–413  ·  view source on GitHub ↗

Send a message from the bridge to WhatsApp

(msg config.Message)

Source from the content-addressed store, hash-verified

349
350// Send a message from the bridge to WhatsApp
351func (b *Bwhatsapp) Send(msg config.Message) (string, error) {
352 groupJID, _ := types.ParseJID(msg.Channel)
353
354 b.Log.Debugf("=> Receiving %#v", msg)
355
356 // Delete message
357 if msg.Event == config.EventMsgDelete {
358 if msg.ID == "" {
359 // No message ID in case action is executed on a message sent before the bridge was started
360 // and then the bridge cache doesn't have this message ID mapped
361 return "", nil
362 }
363
364 _, err := b.wc.RevokeMessage(groupJID, msg.ID)
365
366 return "", err
367 }
368
369 // Edit message
370 if msg.ID != "" {
371 b.Log.Debugf("updating message with id %s", msg.ID)
372
373 if b.GetString("editsuffix") != "" {
374 msg.Text += b.GetString("EditSuffix")
375 } else {
376 msg.Text += " (edited)"
377 }
378 }
379
380 // Handle Upload a file
381 if msg.Extra["file"] != nil {
382 fi := msg.Extra["file"][0].(config.FileInfo)
383 filetype := mime.TypeByExtension(filepath.Ext(fi.Name))
384
385 b.Log.Debugf("Extra file is %#v", filetype)
386
387 // TODO: add different types
388 // TODO: add webp conversion
389 switch filetype {
390 case "image/jpeg", "image/png", "image/gif":
391 return b.PostImageMessage(msg, filetype)
392 case "video/mp4", "video/3gpp": // TODO: Check if codecs are supported by WA
393 return b.PostVideoMessage(msg, filetype)
394 case "audio/ogg":
395 return b.PostAudioMessage(msg, "audio/ogg; codecs=opus") // TODO: Detect if it is actually OPUS
396 case "audio/aac", "audio/mp4", "audio/amr", "audio/mpeg":
397 return b.PostAudioMessage(msg, filetype)
398 default:
399 return b.PostDocumentMessage(msg, filetype)
400 }
401 }
402
403 text := msg.Username + msg.Text
404
405 var message proto.Message
406
407 message.Conversation = &text
408

Callers

nothing calls this directly

Calls 6

PostImageMessageMethod · 0.95
PostVideoMessageMethod · 0.95
PostAudioMessageMethod · 0.95
PostDocumentMessageMethod · 0.95
SendMessageMethod · 0.80
GetStringMethod · 0.65

Tested by

no test coverage detected