You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
720 B
Go
42 lines
720 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/Rhymen/go-whatsapp"
|
|
)
|
|
|
|
type MessageHandler struct {
|
|
Action MessageAction
|
|
Jid string
|
|
}
|
|
|
|
type MessageAction func() error
|
|
|
|
func MakeTextMessageAction(b *BridgeContext, m whatsapp.TextMessage) MessageAction {
|
|
return func() error {
|
|
JID := m.Info.RemoteJid
|
|
|
|
DCID, err := b.GetOrCreateDCIDForJID(JID, m.Info.RemoteJid != m.Info.SenderJid)
|
|
|
|
if err != nil {
|
|
log.Println(err)
|
|
b.SendLog(err.Error())
|
|
}
|
|
|
|
senderName := m.Info.Source.GetParticipant()
|
|
contact, ok := b.WhappConn.Store.Contacts[senderName]
|
|
if ok {
|
|
senderName = contact.Name
|
|
}
|
|
|
|
b.DCContext.SendTextMessage(
|
|
DCID,
|
|
fmt.Sprintf("%s:\n%s", senderName, m.Text),
|
|
)
|
|
|
|
return nil
|
|
}
|
|
}
|