diff --git a/go.mod b/go.mod index 9c66844..552c537 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/prometheus/client_golang v1.14.0 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/tidwall/gjson v1.14.3 - go.mau.fi/whatsmeow v0.0.0-20221113135643-05e0c80bc669 + go.mau.fi/whatsmeow v0.0.0-20221117205735-357841c4ff30 golang.org/x/image v0.1.0 golang.org/x/net v0.2.0 google.golang.org/protobuf v1.28.1 diff --git a/go.sum b/go.sum index 964ad2e..fd71e39 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,8 @@ github.com/yuin/goldmark v1.5.3 h1:3HUJmBFbQW9fhQOzMgseU134xfi6hU+mjWywx5Ty+/M= github.com/yuin/goldmark v1.5.3/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.mau.fi/libsignal v0.0.0-20221015105917-d970e7c3c9cf h1:mzPxXBgDPHKDHMVV1tIWh7lwCiRpzCsXC0gNRX+K07c= go.mau.fi/libsignal v0.0.0-20221015105917-d970e7c3c9cf/go.mod h1:XCjaU93vl71YNRPn059jMrK0xRDwVO5gKbxoPxow9mQ= -go.mau.fi/whatsmeow v0.0.0-20221113135643-05e0c80bc669 h1:pnt9YTRgOKN5eeq67F2vjfsDPu2BnmXx7f2RGZVFjIc= -go.mau.fi/whatsmeow v0.0.0-20221113135643-05e0c80bc669/go.mod h1:elpwNbr2EwG1kadbswg+fKjlWffYUmOxqvx7Q8uX9YE= +go.mau.fi/whatsmeow v0.0.0-20221117205735-357841c4ff30 h1:AVHEkGJSI6NsdbxVs9YEGPFR68uru1Ke/hH72EqzGpk= +go.mau.fi/whatsmeow v0.0.0-20221117205735-357841c4ff30/go.mod h1:2yweL8nczvtlIxkrvCb0y8xiO13rveX9lJPambwYV/E= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.2.0 h1:BRXPfhNivWL5Yq0BGQ39a2sW6t44aODpfxkWjYdzewE= diff --git a/portal.go b/portal.go index dcef4fb..020e64c 100644 --- a/portal.go +++ b/portal.go @@ -383,7 +383,7 @@ func containsSupportedMessage(waMsg *waProto.Message) bool { waMsg.DocumentMessage != nil || waMsg.ContactMessage != nil || waMsg.LocationMessage != nil || waMsg.LiveLocationMessage != nil || waMsg.GroupInviteMessage != nil || waMsg.ContactsArrayMessage != nil || waMsg.HighlyStructuredMessage != nil || waMsg.TemplateMessage != nil || waMsg.TemplateButtonReplyMessage != nil || - waMsg.ListMessage != nil || waMsg.ListResponseMessage != nil + waMsg.ListMessage != nil || waMsg.ListResponseMessage != nil || waMsg.PollCreationMessage != nil } func getMessageType(waMsg *waProto.Message) string { @@ -414,6 +414,10 @@ func getMessageType(waMsg *waProto.Message) string { return "group invite" case waMsg.ReactionMessage != nil: return "reaction" + case waMsg.PollCreationMessage != nil: + return "poll create" + case waMsg.PollUpdateMessage != nil: + return "poll update" case waMsg.ProtocolMessage != nil: switch waMsg.GetProtocolMessage().GetType() { case waProto.ProtocolMessage_REVOKE: @@ -527,6 +531,8 @@ func (portal *Portal) convertMessage(intent *appservice.IntentAPI, source *User, return portal.convertListMessage(intent, source, waMsg.GetListMessage()) case waMsg.ListResponseMessage != nil: return portal.convertListResponseMessage(intent, waMsg.GetListResponseMessage()) + case waMsg.PollCreationMessage != nil: + return portal.convertPollCreationMessage(intent, waMsg.GetPollCreationMessage()) case waMsg.ImageMessage != nil: return portal.convertMediaMessage(intent, source, info, waMsg.GetImageMessage(), "photo", isBackfill) case waMsg.StickerMessage != nil: @@ -2089,6 +2095,37 @@ func (portal *Portal) convertListResponseMessage(intent *appservice.IntentAPI, m } } +func (portal *Portal) convertPollCreationMessage(intent *appservice.IntentAPI, msg *waProto.PollCreationMessage) *ConvertedMessage { + optionsListText := make([]string, len(msg.GetOptions())) + optionsListHTML := make([]string, len(msg.GetOptions())) + optionNames := make([]string, len(msg.GetOptions())) + for i, opt := range msg.GetOptions() { + optionNames[i] = opt.GetOptionName() + optionsListText[i] = fmt.Sprintf("%d. %s\n", i+1, optionNames[i]) + optionsListHTML[i] = fmt.Sprintf("
  • %s
  • ", event.TextToHTML(optionNames[i])) + } + body := fmt.Sprintf("%s\n\n%s", msg.GetName(), strings.Join(optionsListText, "\n")) + formattedBody := fmt.Sprintf("

    %s

      %s
    ", event.TextToHTML(msg.GetName()), strings.Join(optionsListHTML, "")) + return &ConvertedMessage{ + Intent: intent, + Type: event.EventMessage, + Content: &event.MessageEventContent{ + Body: body, + MsgType: event.MsgText, + Format: event.FormatHTML, + FormattedBody: formattedBody, + }, + Extra: map[string]any{ + "fi.mau.whatsapp.poll": map[string]any{ + "options": optionNames, + "max_choices": msg.GetSelectableOptionsCount(), + }, + }, + ReplyTo: GetReply(msg.GetContextInfo()), + ExpiresIn: msg.GetContextInfo().GetExpiration(), + } +} + func (portal *Portal) convertLiveLocationMessage(intent *appservice.IntentAPI, msg *waProto.LiveLocationMessage) *ConvertedMessage { content := &event.MessageEventContent{ Body: "Started sharing live location",