summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/Rhymen/go-whatsapp/message.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2021-05-30 00:25:30 +0200
committerGitHub <noreply@github.com>2021-05-30 00:25:30 +0200
commit4091b6f6b4fe01876f8720332675f9c69be39541 (patch)
tree07a1f2b2eeba6fb680b5edc19d2d38ec81243c0a /vendor/github.com/Rhymen/go-whatsapp/message.go
parent766f35554e16ee5462370be714ef29b71745d478 (diff)
downloadmatterbridge-msglm-4091b6f6b4fe01876f8720332675f9c69be39541.tar.gz
matterbridge-msglm-4091b6f6b4fe01876f8720332675f9c69be39541.tar.bz2
matterbridge-msglm-4091b6f6b4fe01876f8720332675f9c69be39541.zip
Update vendor (#1498)
Diffstat (limited to 'vendor/github.com/Rhymen/go-whatsapp/message.go')
-rw-r--r--vendor/github.com/Rhymen/go-whatsapp/message.go119
1 files changed, 118 insertions, 1 deletions
diff --git a/vendor/github.com/Rhymen/go-whatsapp/message.go b/vendor/github.com/Rhymen/go-whatsapp/message.go
index 34fc02af..cbcb93b4 100644
--- a/vendor/github.com/Rhymen/go-whatsapp/message.go
+++ b/vendor/github.com/Rhymen/go-whatsapp/message.go
@@ -65,6 +65,10 @@ func (wac *Conn) Send(msg interface{}) (string, error) {
msgProto = GetLiveLocationProto(m)
case ContactMessage:
msgProto = getContactMessageProto(m)
+ case ProductMessage:
+ msgProto = getProductMessageProto(m)
+ case OrderMessage:
+ msgProto = getOrderMessageProto(m)
default:
return "ERROR", fmt.Errorf("cannot match type %T, use message types declared in the package", msg)
}
@@ -258,7 +262,7 @@ func getInfoProto(info *MessageInfo) *proto.WebMessageInfo {
}
info.FromMe = true
- status := proto.WebMessageInfo_WEB_MESSAGE_INFO_STATUS(info.Status)
+ status := proto.WebMessageInfo_WebMessageInfoStatus(info.Status)
return &proto.WebMessageInfo{
Key: &proto.MessageKey{
@@ -802,6 +806,113 @@ func getContactMessageProto(msg ContactMessage) *proto.WebMessageInfo {
return p
}
+/*
+OrderMessage represents a order message.
+*/
+
+type OrderMessage struct {
+ Info MessageInfo
+ OrderId string
+ Thumbnail []byte
+ ItemCount int32
+ Status proto.OrderMessage_OrderMessageOrderStatus
+ Surface proto.OrderMessage_OrderMessageOrderSurface
+ Message string
+ OrderTitle string
+ SellerJid string
+ Token string
+ TotalAmount1000 int64
+ TotalCurrencyCode string
+ ContextInfo ContextInfo
+}
+
+func getOrderMessage(msg *proto.WebMessageInfo) OrderMessage {
+ order := msg.GetMessage().GetOrderMessage()
+
+ orderMessage := OrderMessage{
+ Info: getMessageInfo(msg),
+ OrderId: order.GetOrderId(),
+ Thumbnail: order.GetThumbnail(),
+ ItemCount: order.GetItemCount(),
+ Status: order.GetStatus(),
+ Surface: order.GetSurface(),
+ Message: order.GetMessage(),
+ OrderTitle: order.GetOrderTitle(),
+ SellerJid: order.GetSellerJid(),
+ Token: order.GetToken(),
+ TotalAmount1000: order.GetTotalAmount1000(),
+ TotalCurrencyCode: order.GetTotalCurrencyCode(),
+ ContextInfo: getMessageContext(order.GetContextInfo()),
+ }
+
+ return orderMessage
+}
+
+func getOrderMessageProto(msg OrderMessage) *proto.WebMessageInfo {
+ p := getInfoProto(&msg.Info)
+ contextInfo := getContextInfoProto(&msg.ContextInfo)
+
+ p.Message = &proto.Message{
+ OrderMessage: &proto.OrderMessage{
+ Thumbnail: msg.Thumbnail,
+ ItemCount: &msg.ItemCount,
+ Status: &msg.Status,
+ Surface: &msg.Surface,
+ Message: &msg.Message,
+ OrderTitle: &msg.OrderTitle,
+ SellerJid: &msg.SellerJid,
+ Token: &msg.Token,
+ TotalAmount1000: &msg.TotalAmount1000,
+ TotalCurrencyCode: &msg.TotalCurrencyCode,
+ ContextInfo: contextInfo,
+ },
+ }
+
+ return p
+}
+
+/*
+ProductMessage represents a product message.
+*/
+
+type ProductMessage struct {
+ Info MessageInfo
+ Product *proto.ProductSnapshot
+ BusinessOwnerJid string
+ Catalog *proto.CatalogSnapshot
+ ContextInfo ContextInfo
+}
+
+func getProductMessage(msg *proto.WebMessageInfo) ProductMessage {
+ prod := msg.GetMessage().GetProductMessage()
+
+ productMessage := ProductMessage{
+ Info: getMessageInfo(msg),
+ Product: prod.GetProduct(),
+ BusinessOwnerJid: prod.GetBusinessOwnerJid(),
+ Catalog: prod.GetCatalog(),
+ ContextInfo: getMessageContext(prod.GetContextInfo()),
+ }
+
+ return productMessage
+}
+
+func getProductMessageProto(msg ProductMessage) *proto.WebMessageInfo {
+ p := getInfoProto(&msg.Info)
+ contextInfo := getContextInfoProto(&msg.ContextInfo)
+
+ p.Message = &proto.Message{
+ ProductMessage: &proto.ProductMessage{
+ Product: msg.Product,
+ BusinessOwnerJid: &msg.BusinessOwnerJid,
+ Catalog: msg.Catalog,
+ ContextInfo: contextInfo,
+ },
+ }
+
+ return p
+}
+
func ParseProtoMessage(msg *proto.WebMessageInfo) interface{} {
switch {
@@ -836,6 +947,12 @@ func ParseProtoMessage(msg *proto.WebMessageInfo) interface{} {
case msg.GetMessage().GetContactMessage() != nil:
return getContactMessage(msg)
+ case msg.GetMessage().GetProductMessage() != nil:
+ return getProductMessage(msg)
+
+ case msg.GetMessage().GetOrderMessage() != nil:
+ return getOrderMessage(msg)
+
default:
//cannot match message
return ErrMessageTypeNotImplemented