Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List and Button messages appearing only at the sender account #305

Closed
hajsf opened this issue Dec 22, 2022 · 9 comments
Closed

List and Button messages appearing only at the sender account #305

hajsf opened this issue Dec 22, 2022 · 9 comments

Comments

@hajsf
Copy link

hajsf commented Dec 22, 2022

I've the below code:

package utils

import (
	"context"
	"strconv"
	"wa/Enum"
	"wa/api"
	"wa/global"

	waProto "go.mau.fi/whatsmeow/binary/proto"
	"google.golang.org/protobuf/proto"
)

func MainMenu(sender, welcome string) {
	msg := &waProto.ListMessage{
		Title:       proto.String(welcome),
		Description: proto.String("يرجى تحديد سبب التواصل"),
		ButtonText:  proto.String("أنقر هنا  👈"),
		ListType:    waProto.ListMessage_SINGLE_SELECT.Enum(),
		Sections: []*waProto.ListMessage_Section{
			{
				Title: proto.String("لدي إستفسار بخصوص:"),
				Rows: []*waProto.ListMessage_Row{
					{
						RowId: proto.String(strconv.Itoa(Enum.Discount)),
						Title: proto.String("عمادة القبول والتسجيل"),
					},
					{
						RowId: proto.String(strconv.Itoa(Enum.Discount)),
						Title: proto.String("عمادة شؤون المكتبات"),
					},
					{
						RowId: proto.String(strconv.Itoa(Enum.Discount)),
						Title: proto.String("مواقع كليات وفروع جامعة الملك خالد"),
					},
				},
			},
		},
	}

	targetJID, ok := ParseJID(sender)
	if !ok {
		return
	}

	send, err := api.Client.SendMessage(context.Background(), targetJID, "", &waProto.Message{
		ListMessage: msg,
	}) // jid = recipient
	if err != nil {
		global.Log.Errorf("Error sending message: %v", err)
	} else {
		global.Log.Infof("Message sent (server timestamp: %s)", send)
	}

	send2, err := api.Client.SendMessage(context.Background(), targetJID, "", &waProto.Message{
		Conversation: proto.String("Hello, World!"),
	})
	if err != nil {
		global.Log.Errorf("Error sending message: %v", err)
	} else {
		global.Log.Infof("Message sent (server timestamp: %s)", send2)
	}

}

But the list message is seen only at th esender account (i.e. the account connected to the app using whatsmeow package) and not seeing it at the recieved account, same happen with Button Message, but sending a conversation message is different as it is appearing at both accounts

	msg := &waProto.ButtonsMessage{
		ContentText: proto.String("لدي إستفسار بخصوص:"),
		HeaderType:  waProto.ButtonsMessage_EMPTY.Enum(),
		Buttons: []*waProto.ButtonsMessage_Button{
			{
				ButtonId:       proto.String(strconv.Itoa(Enum.Yes)),
				ButtonText:     &waProto.ButtonsMessage_Button_ButtonText{DisplayText: proto.String("نعم")},
				Type:           waProto.ButtonsMessage_Button_RESPONSE.Enum(),
				NativeFlowInfo: &waProto.ButtonsMessage_Button_NativeFlowInfo{},
			},
			{
				ButtonId:       proto.String(strconv.Itoa(Enum.No)),
				ButtonText:     &waProto.ButtonsMessage_Button_ButtonText{DisplayText: proto.String("لا")},
				Type:           waProto.ButtonsMessage_Button_RESPONSE.Enum(), //proto.ButtonsMessage_Button_Type.Enum,
				NativeFlowInfo: &waProto.ButtonsMessage_Button_NativeFlowInfo{},
			},
		},
	}

	send, err := api.Client.SendMessage(context.Background(), targetJID, "", &waProto.Message{
		ButtonsMessage: msg,
	})

image

@hrizal
Copy link

hrizal commented Dec 23, 2022

in my case, its appears on latest app version, but not on an older version and on whatsapp web

@hajsf
Copy link
Author

hajsf commented Dec 23, 2022

in my case, its appears on latest app version, but not on an older version and on whatsapp web

I do have the latest app version at Android that is version 2.22.24.78, Is it the same you have? are you at Android or iOS?

@hrizal
Copy link

hrizal commented Dec 23, 2022

did you wrap it with ViewOnceMessage ?

			msg := &waProto.Message{
				ViewOnceMessage: &waProto.FutureProofMessage{				
				<-- button message here -->
			}}

@hajsf
Copy link
Author

hajsf commented Dec 23, 2022

did you wrap it with ViewOnceMessage

No, do I need to wrap it?

@hrizal
Copy link

hrizal commented Dec 23, 2022

yups
check this ##237

@hajsf
Copy link
Author

hajsf commented Dec 23, 2022

yups check this ##237

Thanks a lot, it is working fine now:

package utils

import (
	"context"
	"fmt"
	"strconv"
	"strings"
	"wa/Enum"
	"wa/api"
	"wa/global"

	waProto "go.mau.fi/whatsmeow/binary/proto"
	"google.golang.org/protobuf/proto"
)

func MainMenu(sender, welcome string) {
	targetJID, ok := ParseJID(sender)
	if !ok {
		return
	}

	msg1 := &waProto.ListMessage{
		Title:       proto.String(welcome),
		Description: proto.String("يرجى تحديد سبب التواصل"),
		ButtonText:  proto.String("أنقر هنا  👈"),
		ListType:    waProto.ListMessage_SINGLE_SELECT.Enum(),
		Sections: []*waProto.ListMessage_Section{
			{
				Title: proto.String("لدي إستفسار بخصوص:"),
				Rows: []*waProto.ListMessage_Row{
					{
						RowId: proto.String(strconv.Itoa(Enum.Discount)),
						Title: proto.String("عمادة القبول والتسجيل"),
						//	Description: proto.String("عمادة القبول والتسجيل"),
					},
					{
						RowId: proto.String(strconv.Itoa(Enum.Discount)),
						Title: proto.String("عمادة شؤون المكتبات"),
					},
					{
						RowId: proto.String(strconv.Itoa(Enum.Discount)),
						Title: proto.String("مواقع كليات وفروع جامعة الملك خالد"),
					},
				},
			},
		},
		//	ProductListInfo: &waProto.ListMessage_ProductListInfo{},
		//	FooterText:      new(string),
		//	ContextInfo:     &waProto.ContextInfo{},
	}

	msg2 := &waProto.ButtonsMessage{
		ContentText: proto.String("لدي إستفسار بخصوص:"),
		HeaderType:  waProto.ButtonsMessage_EMPTY.Enum(),
		Buttons: []*waProto.ButtonsMessage_Button{
			{
				ButtonId:       proto.String(strconv.Itoa(Enum.Yes)),
				ButtonText:     &waProto.ButtonsMessage_Button_ButtonText{DisplayText: proto.String("نعم")},
				Type:           waProto.ButtonsMessage_Button_RESPONSE.Enum(),
				NativeFlowInfo: &waProto.ButtonsMessage_Button_NativeFlowInfo{},
			},
			{
				ButtonId:       proto.String(strconv.Itoa(Enum.No)),
				ButtonText:     &waProto.ButtonsMessage_Button_ButtonText{DisplayText: proto.String("لا")},
				Type:           waProto.ButtonsMessage_Button_RESPONSE.Enum(), //proto.ButtonsMessage_Button_Type.Enum,
				NativeFlowInfo: &waProto.ButtonsMessage_Button_NativeFlowInfo{},
			},
		},
	}

	send, err := api.Client.SendMessage(context.Background(), targetJID, "", &waProto.Message{
		ViewOnceMessage: &waProto.FutureProofMessage{
			Message: &waProto.Message{
				ListMessage: msg1,
			},
		}})

	if err != nil {
		global.Log.Errorf("Error sending message: %v", err)
	} else {
		global.Log.Infof("Message sent (server timestamp: %s)", send)
	}

	send3, err := api.Client.SendMessage(context.Background(), targetJID, "", &waProto.Message{
		ViewOnceMessage: &waProto.FutureProofMessage{
			Message: &waProto.Message{
				ButtonsMessage: msg2,
			},
		}})

	if err != nil {
		global.Log.Errorf("Error sending message: %v", err)
	} else {
		global.Log.Infof("Message sent (server timestamp: %s)", send3)
	}

	var content strings.Builder
	content.WriteString(welcome)
	content.WriteString("\n")
	content.WriteString("الرجاء إختيار خيار من أدناه")
	content.WriteString("\n")
	content.WriteString("1️⃣ إستفسارات عمادة القبول و التسجيل")
	content.WriteString("\n")
	content.WriteString("2️⃣ إستفسارات عمادة شؤون المكتبات")
	content.WriteString("\n")
	content.WriteString("3️⃣ مواقع كليات و فروع الجامعه")
	content.WriteString("\n")
	send2, err := api.Client.SendMessage(context.Background(), targetJID, "", &waProto.Message{
		Conversation: proto.String(content.String()),
	})
	if err != nil {
		global.Log.Errorf("Error sending message: %v", err)
	} else {
		global.Log.Infof("Message sent (server timestamp: %s)", send2)
	}
	fmt.Println(send2)

}

@hajsf hajsf closed this as completed Dec 23, 2022
@1337-sys
Copy link

Doesn't work when sending the template message. For example: #173

@Sandeep-Narahari
Copy link

func (m Module) eventHandler(evt interface{}) {
switch v := evt.(type) {
case *events.Message:
fmt.Println("FIsrsds", v.Info.Sender.User)
fmt.Println("Message", v.Info.Chat.User)
if strings.Contains(types.JID{
User: v.Info.Sender.User,
}.User, "919177291158") {
if v.Message.GetConversation() == "start" {
fmt.Println("INSIde START")
sendMsgButton := &waProto.ButtonsMessage{
HeaderType: waProto.ButtonsMessage_TEXT.Enum(),
ContentText: proto.String("Please click the button to call the API"),
FooterText: proto.String("This is the footer text"),
Buttons: []*waProto.ButtonsMessage_Button{
{
ButtonId: proto.String("send_api_request"),
ButtonText: &waProto.ButtonsMessage_Button_ButtonText{
DisplayText: proto.String("Send API Request"),
},
Type: waProto.ButtonsMessage_Button_NATIVE_FLOW.Enum(),
},
},
}

			_, err := m.whatsAppClient.SendMessage(context.Background(), types.JID{
				User:   "919177291158",
				Server: types.DefaultUserServer,
			}, &waProto.Message{ViewOnceMessage: &waProto.FutureProofMessage{
				Message: &waProto.Message{
					ButtonsMessage: sendMsgButton,
				},
			}})
			if err != nil {
				println("ERROR: ", err)
			}
		} else {
			if v.Message.ButtonsResponseMessage != nil {
				selectedId := v.Message.ButtonsResponseMessage.SelectedButtonId
				fmt.Println("SELECTED BUTTON D D", *selectedId)
				if *selectedId == "send_api_request" {

					resp, err := http.Get("http://localhost:9996/message")
					if err != nil {
						fmt.Println(err.Error())
					}
					if resp.StatusCode == http.StatusOK {
						_, err := m.whatsAppClient.SendMessage(context.Background(), types.JID{
							User:   "XXXXXXXXXX",
							Server: types.DefaultUserServer,
						}, &waProto.Message{Conversation: proto.String("Request Sent Successfull")})
						if err != nil {
							println("ERROR:Send Mesage in chat: ", err)
						}
					} else {
						_, err := m.whatsAppClient.SendMessage(context.Background(), types.JID{
							User:   "XXXXXXXX",
							Server: types.DefaultUserServer,
						}, &waProto.Message{Conversation: proto.String("Request was not Successfull")})
						if err != nil {
							println("ERROR:Send Mesage in chat: ", err)
						}
					}
					defer resp.Body.Close()
					body, err := ioutil.ReadAll(resp.Body)
					if err != nil {
						fmt.Println("ERR: Read Response Body", err)
					}
					fmt.Println("RESP", body)

				}
			}

		}

	}
}

}

@Sandeep-Narahari
Copy link

No able to see the button messages in the recipient mobile after using view once also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants