Rhymen / go-whatsapp

WhatsApp Web API
MIT License
2.07k stars 492 forks source link

WhatsApp business, how to get cart details #539

Closed beshoo closed 3 years ago

beshoo commented 3 years ago

Hi, As we know, WhatsApp Business has catalog feature. Now, if you go to someone catalog, you can send a cart order.

The recipient of the order ( the WhatsApp business ) can see the order details from the web.

Once user clicks on the order details button. WhatsApp web sen unencrypted soket request. Something like this.. 745.--26,,["query","order",{"id":"35206.44710-1","orderId":"961297227737359","imageWidth":"80","imageHeight":"80","token":"AR5zzk+vCTfMZNGd7sbYCJiLXWUMqLZaC8S+SjDABOZX1g=="}]

Now, most of the variables are captured from the handler via this PL

https://github.com/Rhymen/go-whatsapp/pull/518

the problem is the {"id":"35206.44710-1"} is not included with the handler returned result.

Ps: let's say you have 5 orders in the chat. If you click on any one on the first time, The latest number will be one, -1 now if you click on any other order, the number will be +1..which will be 2.

The id it self is not sate, but each time you refresh the chat you will nit a different number and different token.

In order to know what user's asking fir un their orders we need to send this json to grep the results but what is the correct method?

Regard

Romerito007 commented 3 years ago

See if it helps you!

func (wac *Conn) Orders() (<-chan string, error) { data := []interface{}{"query", "order", map[string]string{ "orderId": "275046030837098", "id": "17582.4263-5", "imageHeight": strconv.Itoa(80), "imageWidth": strconv.Itoa(80), "token": "AR6DX3HdQbd2fh7p7LlpUXXgyBkHAPdXEMAtl3504NifEw==", }} return wac.writeJSON(data) }

func (wac *Conn) Products() (<-chan string, error) { data := []interface{}{"query", "bizCatalog", map[string]string{ "catalogWid": "5544840xxxxx@s.whatsapp.net", "limit": strconv.Itoa(10), "height": strconv.Itoa(100), "width": strconv.Itoa(100), "stanza_id": "17582.4263-4", "type": "get_product_catalog_reh", }} return wac.writeJSON(data) }

beshoo commented 3 years ago

@Romerito007 Thank you for your reply but I don't understand, how can we get the "id": "17582.4263" !

Romerito007 commented 3 years ago

@ Romerito007 Obrigado pela sua resposta, mas não entendi, como podemos obter o "id": "17582.4263"!

if changing the id makes no difference, test it by changing this id! Sorry about my English.

beshoo commented 3 years ago

Do you mean it is a random id? cos I test random id and it returns an error 400

beshoo commented 3 years ago

Look, this is not going to work this way, You made the PL, and thank you so much for that. Can you make the handler return the order details as well along with the order?

beshoo commented 3 years ago

@Romerito007 I test your code but something does not correct it returns error 400. I am not sure if it work with you.

Anyway, can you Update your PL to return order information?

Romerito007 commented 3 years ago

@ Romerito007 Eu testo seu código, mas algo não corrige retorna o erro 400. Não tenho certeza se funciona com você.

De qualquer forma, você pode atualizar seu PL para retornar as informações do pedido?

it's working, I don't get 400 status, just 500 or 401

beshoo commented 3 years ago

@Romerito007 thin it is not working you have to get the result of the request with a 200 status code! Did you get the order json code with the response?

Romerito007 commented 3 years ago

yes returns status 200

Captura de tela de 2021-03-27 16-22-50 Captura de tela de 2021-03-27 16-24-09

beshoo commented 3 years ago

I think it works for me SOLVED

GabrielBragaGit commented 3 years ago

How did you do to work?

beshoo commented 3 years ago
func randInt(min int, max int) int {
    return min + rand.Intn(max-min)
}
       rand.Seed(time.Now().UTC().UnixNano())
    id:= strconv.Itoa(randInt(11111, 99999))+"."+strconv.Itoa(randInt(11111, 99999))+"-1"

    datas:= []interface{}{"query", "order", map[string]string{"id":id ,"orderId":message.OrderId,"imageWidth":"80","imageHeight":"80","token":message.Token}}

    order_details,_ := wh.Wac.WriteJson(datas)
    output := <-order_details
    log.Warnf("JSON %v", output)
GabrielBragaGit commented 3 years ago

@beshoo and you are using the functions from @Romerito007's PR?

beshoo commented 3 years ago

Yes, but he has to modify his PL to add this to the response context @Romerito007 please can you add it so I can merge the PL?