feat(whatsapp): 🎉 Add extended sending and template management
* Implemented new endpoints for sending various message types: - Audio - Sticker - Location - Contacts - Interactive messages - Template messages - Flow messages - Reactions - Marking messages as read * Added template management endpoints: - List templates - Upload templates - Delete templates * Introduced flow management endpoints: - List flows - Create flows - Get flow details - Upload flow assets - Publish flows - Delete flows * Added phone number management endpoints: - List phone numbers - Request verification code - Verify code * Enhanced media management with delete media endpoint. * Updated dependencies.
This commit is contained in:
71
pkg/whatsapp/businessapi/flows.go
Normal file
71
pkg/whatsapp/businessapi/flows.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package businessapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// ListFlows returns all flows for the business account.
|
||||
func (c *Client) ListFlows(ctx context.Context) (*FlowListResponse, error) {
|
||||
if c.config.BusinessAccountID == "" {
|
||||
return nil, errNoBusinessAccount
|
||||
}
|
||||
|
||||
params := url.Values{
|
||||
"fields": {"id,name,status,categories,created_at,updated_at,endpoint_url,preview_url,signed_preview_url,signed_flow_url"},
|
||||
}
|
||||
|
||||
var resp FlowListResponse
|
||||
if err := c.graphAPIGet(ctx, c.config.BusinessAccountID+"/flows", params, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// CreateFlow creates a new flow and returns its ID.
|
||||
func (c *Client) CreateFlow(ctx context.Context, flow FlowCreateRequest) (*FlowCreateResponse, error) {
|
||||
if c.config.BusinessAccountID == "" {
|
||||
return nil, errNoBusinessAccount
|
||||
}
|
||||
|
||||
var resp FlowCreateResponse
|
||||
if err := c.graphAPIPost(ctx, c.config.BusinessAccountID+"/flows", flow, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// GetFlow returns details for a single flow.
|
||||
func (c *Client) GetFlow(ctx context.Context, flowID string) (*FlowInfo, error) {
|
||||
params := url.Values{
|
||||
"fields": {"id,name,status,categories,created_at,updated_at,endpoint_url,preview_url,signed_preview_url,signed_flow_url"},
|
||||
}
|
||||
|
||||
var resp FlowInfo
|
||||
if err := c.graphAPIGet(ctx, flowID, params, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
||||
|
||||
// UpdateFlowAssets uploads a screens JSON definition to an existing flow (must be in DRAFT).
|
||||
func (c *Client) UpdateFlowAssets(ctx context.Context, flowID string, screensJSON string) error {
|
||||
fields := map[string]string{
|
||||
"asset_type": "SCREENS_JSON",
|
||||
"asset_data": screensJSON,
|
||||
}
|
||||
|
||||
var resp FlowActionResponse
|
||||
return c.graphAPIPostForm(ctx, flowID+"/assets", fields, &resp)
|
||||
}
|
||||
|
||||
// PublishFlow transitions a DRAFT flow to PUBLISHED.
|
||||
func (c *Client) PublishFlow(ctx context.Context, flowID string) error {
|
||||
var resp FlowActionResponse
|
||||
return c.graphAPIPost(ctx, flowID+"?action=PUBLISH", nil, &resp)
|
||||
}
|
||||
|
||||
// DeleteFlow permanently removes a flow.
|
||||
func (c *Client) DeleteFlow(ctx context.Context, flowID string) error {
|
||||
return c.graphAPIDelete(ctx, flowID, nil)
|
||||
}
|
||||
Reference in New Issue
Block a user