qrcodes

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package qrcodes provides API implementations to manage QR codes for WhatsApp Business. It contains functions to create, retrieve, update and delete QR codes using the WhatsApp Business Management API.

Customers can scan a QR code from their phone to quickly begin a conversation with your business. The WhatsApp Business Management API allows you to create and access these QR codes and associated short links.

If you can use the Business Manager to manage your QR codes instead of the API, see Manage your WhatsApp QR Codes here https://web.facebook.com/business/help/890732351439459?_rdc=1&_rdr

Before using this API in your application. You must have the following:

Create a QR StatusCode Message

Example:

resp, err := qrcodes.Create(context.Background(), http.DefaultClient,&qrcodes.CreateRequest{
	PrefilledMessage: "Hello World",
	ImageFormat:      qrcodes.ImageFormatPNG,
})
// handle error
......
// handle response
.......

This is equivalent to the following API call using curl which has been reformatted for readability:

curl -X POST "https://graph.facebook.com/v16.0/{phone-number-ID}/message_qrdls
?prefilled_message="Hello World"
&generate_qr_image=PNG
&access_token={user-access-token}"

On success, a JSON array is returned:

{
	"code": "{qr-code-id}",
	"prefilled_message": "{business message text}",
	"deep_link_url": "{short-link-to-qr-code}",
	"qr_image_url": "{image-url}"
}

Retrieve All QR StatusCode Messages

Example:

resp, err := qrcodes.List(context.Background(), http.DefaultClient, "phoneNumberID","token")
// handle error
......
// handle response
......

This is an equivalent to the following curl command:

	curl -X GET "https://graph.facebook.com/v16.0/{phone-number-ID}/message_qrdls
	    &access_token={user-access-token}"
 On success, a JSON array is returned:

	{
		"data": [
			{
				"code": "ANOVZ6RINRD7G1",
				"prefilled_message": "I need help with my account.",
				"deep_link_url": "https://wa.me/message/ANOVZ6RINRD7G1"
			},
			{
				"code": "TNGSHG326AIHH1",
             "prefilled_message": "What are your store hours?",
             "deep_link_url": "https://wa.me/message/TNGSHG326AIHH1"
         },
         {
             "code": "R3LUI5KILJUYA1",
             "prefilled_message": "When is the next sale?",
             "deep_link_url": "https://wa.me/message/R3LUI5KILJUYA1"
         },

     ]
	}

Retrieve a single QR StatusCode

Example Request

Formatted for readability curl -X GET "https://graph.facebook.com/v16.0/{phone-number-ID}/message_qrdls/{qr-code-id}

    &access_token={user-access-token}"
 On success, a JSON array is returned:

 {
     "data": [
         {
             "code": "ANOVZ6RINRD7G1",
             "prefilled_message": "I need help with my account.",
             "deep_link_url": "https://wa.me/message/ANOVZ6RINRD7G1"
         }
     ]
}

Example:

info, err := qrcodes.Get(context.TODO(),http.DefaultClient, "baseURL", "phoneID", "accessToken", "qrCodeID")

Update Details of a QR StatusCode

Example Request

Formatted for readability

 curl -X POST "https://graph.facebook.com/v16.0/{phone-number-ID}/message_qrdls/{qr-code-id}
   ?prefilled_message={new-message-text}
   &access_token={user-access-token}"
 On success, a JSON array is returned:

 {
     "code": "{qr-code-id}",
     "prefilled_message": "{business message text}",
     "deep_link_url": "{short-link-to-qr-code}"
}

Delete QR StatusCode QR codes do not expire. You must delete a QR code in order to retire it.

Formatted (for readability) curl command to delete a QR StatusCode. curl -X DELETE "https://graph.facebook.com/v16.0/{phone-number-ID}/message_qrdls/{qr-code-id}

&access_token={user-access-token}"

On success, a JSON array is returned:

{
	"success": true
}

Index

Constants

This section is empty.

Variables

View Source
var ErrNoDataFound = fmt.Errorf("no data found")
View Source
var ErrUnexpectedResponseCode = fmt.Errorf("unexpected response code")

Functions

This section is empty.

Types

type CreateRequest

type CreateRequest struct {
	PrefilledMessage string      `json:"prefilled_message"`
	ImageFormat      ImageFormat `json:"generate_qr_image"`
}

type CreateResponse

type CreateResponse struct {
	Code             string `json:"code"`
	PrefilledMessage string `json:"prefilled_message"`
	DeepLinkURL      string `json:"deep_link_url"`
	QRImageURL       string `json:"qr_image_url"`
}

func Create

func Create(ctx context.Context, client *http.Client, rtx *RequestContext,
	req *CreateRequest, hooks ...whttp.Hook,
) (*CreateResponse, error)

type ImageFormat

type ImageFormat string
const (
	ImageFormatPNG ImageFormat = "PNG"
	ImageFormatSVG ImageFormat = "SVG"
)

type Information

type Information struct {
	Code             string `json:"code"`
	PrefilledMessage string `json:"prefilled_message"`
	DeepLinkURL      string `json:"deep_link_url"`
}

func Get

func Get(ctx context.Context, client *http.Client, rctx *RequestContext, qrCodeID string,
	hooks ...whttp.Hook,
) (*Information, error)

type ListResponse

type ListResponse struct {
	Data []*Information `json:"data,omitempty"`
}

func List

func List(ctx context.Context, client *http.Client, rctx *RequestContext, hooks ...whttp.Hook) (*ListResponse, error)

type RequestContext

type RequestContext struct {
	BaseURL     string `json:"-"`
	PhoneID     string `json:"-"`
	ApiVersion  string `json:"-"` //nolint: revive,stylecheck
	AccessToken string `json:"-"`
}

type SuccessResponse

type SuccessResponse struct {
	Success bool `json:"success"`
}

func Delete

func Delete(ctx context.Context, client *http.Client, rtx *RequestContext, qrCodeID string,
	hooks ...whttp.Hook,
) (*SuccessResponse, error)

func Update

func Update(ctx context.Context, client *http.Client, rtx *RequestContext, qrCodeID string,
	req *CreateRequest, hooks ...whttp.Hook) (*SuccessResponse, error,
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL