feat: VTEX client and add_to_cart action support - #149
Merged
Merged
Conversation
Robi9
approved these changes
Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an
add_to_cartWebSocket message type that lets browser clients add or update items in a VTEX shopping cart. The implementation introduces a newpkg/vtexpackage containing an HTTP client for the VTEX Checkout API, wired into the existing WebSocket handler pipeline.New package —
pkg/vtexIClientinterface with a single methodAddOrUpdateCartItem(ctx, vtexAccount, orderFormID, itemID, seller)for testabilityClientimplementation that fetches the current order form (GET), then either adds the item or increments its quantity (POST)MockIClient) for handler-level testsWebSocket integration
add_to_cartcase inParsePayloaddispatchAddToCarthandler validates the payload synchronously, then runs the VTEX API call in a goroutine (non-blocking for the read loop)cart_updatedon success orcart_erroron failure back to the clientHardening
context.WithTimeout(30 s) wrapping the goroutine's VTEX call, enabling cancellation and bounding goroutine lifetimevtexAccountandorderFormIDare validated against^[a-zA-Z0-9][a-zA-Z0-9-]*$before URL interpolation, blocking fragment (#), slash, dot, and query-string injection attacksFiles changed
pkg/vtex/client.gopkg/vtex/client_mock.gopkg/vtex/client_test.gopkg/websocket/application.goVTEXClient vtex.IClienttoAppandNewApppkg/websocket/client.goAddToCarthandler +ParsePayloadcasepkg/websocket/client_test.goapi/main.govtex.NewClient(), passes toNewAppWhy
Enables the webchat widget to add products to a VTEX shopping cart directly from the conversation, supporting e-commerce use cases where a chatbot recommends products and the user can add them without leaving the chat.