Thursday, June 13, 2024
HomeGolangAssist me with a operate - Getting Assist

Assist me with a operate – Getting Assist


Good afternoon, I’ve the next operate:

func generateCarouselContent(attachments string, msg courier.Msg) map[string]interface{} {
carouselContent := make(map[string]interface{}, 0)

for _, attachment := vary attachments {
	_, mediaURL := handlers.SplitAttachment(attachment)
	carouselItem := map[string]interface{}{
		"textual content":  msg.Textual content(),
		"picture": mediaURL,
	}

	buttons := make([]map[string]interface{}, 0) // Slice para almacenar los botones

	for _, quickReplyCarousel := vary msg.QuickReplies() {
		// Verificamos si quickReply es una URL o texto
		if strings.HasPrefix(quickReplyCarousel, "http") {
			buttons = append(buttons, map[string]interface{}{
				"textual content":         "Open URL",
				"kind":         "web_url",
				"postbackData": "myCustomPostbackData",
				"knowledge":         quickReplyCarousel,
			})
		}
	}

	if len(buttons) > 0 {
		carouselItem["buttons"] = buttons // Agregamos los botones al elemento del carrusel si hay alguno
	}

	carouselContent = append(carouselContent, carouselItem)
}

return carouselContent

}

As seen within the picture, it seems 2 occasions within the textual content “Open URL” and I solely need it to look as soon as.

May you assist me or have any recommendations?

Hello @Ivan_Garcia,

I’m not positive if I perceive what the code does. It could appear that buttons accumulates all of the buttons from each quickReplyCarousel. So for every ingredient in msg.QuickReplies(), one button will get added to buttons.

After the loop, the whole buttons map with all buttons in it’s assigned to the map carouselItem with the important thing "buttons".

If msg.QuickReplies() incorporates two components with prefix “http”, buttons will include two buttons named “Open URL”.

Possibly it’s extra of a knowledge drawback than a code drawback.

Whats up Cristophberger, thanks on your assist.

This code is used for RCS messages and notably I’m implementing it in a picture carousel with one hyperlink per picture, as I present within the screenshot, it’s printing 2 hyperlinks.

I hope you’ve made me perceive jejejeje

Regards.

So is my fast “evaluation” of the code right?

In that case, the answer is perhaps to verify what msg.QuickReplies() truly incorporates. If it incorporates two components with prefix http, then clearly, the information delivered to your operate already incorporates this duplicate.

Does this make sense?

To elaborate additional, after discovering the primary fast reply with prefix http, the for loop might break to keep away from accumulating additional strings with the identical prefix.

This could not repair the duplicate knowledge, however at the least forestall the duplicate from showing within the UI.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments