Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
piusalfred committed Jan 14, 2024
1 parent 304eaa4 commit 809c52d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 44 deletions.
34 changes: 13 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
# whatsapp

## implemented
- [x] send text message
- [x] send image message
- [x] send location message
- [x] send contact message
- [x] send template message
- [x] react to message
- [x] mark message as read
- [x] webhooks

# SETUP
## set up
- Have golang installed
- Register as a Meta Developer here https://developers.facebook.com/docs/development/register
- Create an application here https://developers.facebook.com/docs/development/create-an-app and configure
it to enable access to WhatsApp Business Cloud API and Webhooks.

## pre requisites
- You can manage your apps here https://developers.facebook.com/apps/

To be able to test/use this api you need Access Token, Phone number ID and Business ID. For that
tou need to register as a Meta Developer. You can register here https://developers.facebook.com/docs/development/register
- From Whatsapp Developer Dashboard you can try and send a test message to your phone number.
to be sure that everything is working fine before you start using this api. Also you need to
reply to that message to be able to send other messages.

Then create an application here https://developers.facebook.com/docs/development/create-an-app and configre
it to enable access to WhatsApp Business Cloud API.
- Go to [examples/base](examples/base) then create `.env` file that looks like [examples/base/.envrc](examples/base/.envrc)
and add your credentials there.

You can manage your apps here https://developers.facebook.com/apps/

From Whatsapp Developer Dashboard you can try and send a test message to your phone number.
to be sure that everything is working fine before you start using this api.

When all the above is done you can start using this api.
- Run `make run` and wait to receive a message on your phone. Make sure you have sent the template message
first from the Whatsapp Developer Dashboard.
43 changes: 27 additions & 16 deletions pkg/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ type (

// Message is a WhatsApp message. It contains the following fields:
//
// BizOpaqueCallbackData biz_opaque_callback_data (string) Optional. An arbitrary
// 256B string, useful for tracking. For example, you could pass the message template
// ID in this field to track your customer's journey starting from the first message you
// send. You could then track the ROI of different message template types to determine the
// most effective one.
// Any app subscribed to the messages webhook field on the WhatsApp Business Account can get
// this string, as it is included in statuses object within webhook payloads.
// Cloud API does not process this field, it just returns it as part of sent/delivered/read
// message webhooks.
//
// Audio (object) Required when type=audio. A media object containing audio.
//
// Contacts (object) Required when type=contacts. A contacts object.
Expand Down Expand Up @@ -164,22 +174,23 @@ type (
//
// Type (string). Optional. The type of message you want to send. Default: text.
Message struct {
Product string `json:"messaging_product"`
To string `json:"to"`
RecipientType string `json:"recipient_type"`
Type string `json:"type"`
Context *Context `json:"context,omitempty"`
Template *Template `json:"template,omitempty"`
Text *Text `json:"text,omitempty"`
Image *Image `json:"image,omitempty"`
Audio *Audio `json:"audio,omitempty"`
Video *Video `json:"video,omitempty"`
Document *Document `json:"document,omitempty"`
Sticker *Sticker `json:"sticker,omitempty"`
Reaction *Reaction `json:"reaction,omitempty"`
Location *Location `json:"location,omitempty"`
Contacts Contacts `json:"contacts,omitempty"`
Interactive *Interactive `json:"interactive,omitempty"`
Product string `json:"messaging_product"`
BizOpaqueCallbackData string `json:"biz_opaque_callback_data,omitempty"`
To string `json:"to"`
RecipientType string `json:"recipient_type"`
Type string `json:"type"`
Context *Context `json:"context,omitempty"`
Template *Template `json:"template,omitempty"`
Text *Text `json:"text,omitempty"`
Image *Image `json:"image,omitempty"`
Audio *Audio `json:"audio,omitempty"`
Video *Video `json:"video,omitempty"`
Document *Document `json:"document,omitempty"`
Sticker *Sticker `json:"sticker,omitempty"`
Reaction *Reaction `json:"reaction,omitempty"`
Location *Location `json:"location,omitempty"`
Contacts Contacts `json:"contacts,omitempty"`
Interactive *Interactive `json:"interactive,omitempty"`
}

Image Media
Expand Down
15 changes: 8 additions & 7 deletions webhooks/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,14 @@ type (
// back, as it is implied that a message has been delivered if it has been read. The reason for this
// behavior is internal optimization.
Status struct {
ID string `json:"id,omitempty"`
RecipientID string `json:"recipient_id,omitempty"`
StatusValue string `json:"status,omitempty"`
Timestamp int `json:"timestamp,omitempty"`
Conversation *Conversation `json:"conversation,omitempty"`
Pricing *Pricing `json:"pricing,omitempty"`
Errors []*werrors.Error `json:"werrors,omitempty"`
ID string `json:"id,omitempty"`
BizOpaqueCallbackData string `json:"biz_opaque_callback_data,omitempty"`
RecipientID string `json:"recipient_id,omitempty"`
StatusValue string `json:"status,omitempty"`
Timestamp int `json:"timestamp,omitempty"`
Conversation *Conversation `json:"conversation,omitempty"`
Pricing *Pricing `json:"pricing,omitempty"`
Errors []*werrors.Error `json:"errors,omitempty"`
}

// Event is the type of event that occurred and leads to the notification being sent.
Expand Down

0 comments on commit 809c52d

Please sign in to comment.