Modules@robinpath/whatsapp
whatsapp

@robinpath/whatsapp

0.1.1Node.jsPublic

WhatsApp module for RobinPath.

WhatsApp

WhatsApp module for RobinPath.

Package: @robinpath/whatsapp | Category: Messaging | Type: Integration

Authentication

whatsapp.setCredentials "EAABxxx" "1234567890"

Call this once at the start of your script before using any other function. Credentials persist for the duration of the script execution.

Use Cases

Use the whatsapp module when you need to:

  • Send a text message. -- Use whatsapp.sendText to perform this operation
  • Send a pre-approved template message. -- Use whatsapp.sendTemplate to perform this operation
  • Send an image message. -- Use whatsapp.sendImage to perform this operation
  • Send a document message. -- Use whatsapp.sendDocument to perform this operation
  • Send a location message. -- Use whatsapp.sendLocation to perform this operation

Quick Reference

FunctionDescriptionReturns
setCredentialsSet WhatsApp Cloud API credentials.Confirmation message.
sendTextSend a text message.Message send response.
sendTemplateSend a pre-approved template message.Message send response.
sendImageSend an image message.Message send response.
sendDocumentSend a document message.Message send response.
sendLocationSend a location message.Message send response.
sendContactSend contact card(s).Message send response.
markReadMark a message as read.Status response.
getProfileGet the WhatsApp Business profile.Business profile data.
updateProfileUpdate the WhatsApp Business profile.Update response.

Functions

setCredentials

Set WhatsApp Cloud API credentials.

Module: whatsapp | Returns: string -- Confirmation message.

whatsapp.setCredentials "EAABxxx" "1234567890"
ParameterTypeRequiredDescription
accessTokenstringYesPermanent or temporary access token
phoneNumberIdstringYesWhatsApp Business phone number ID

sendText

Send a text message.

Module: whatsapp | Returns: object -- Message send response.

whatsapp.sendText "+1234567890" "Hello from RobinPath!"
ParameterTypeRequiredDescription
tostringYesRecipient phone number (international format)
messagestringYesMessage text

sendTemplate

Send a pre-approved template message.

Module: whatsapp | Returns: object -- Message send response.

whatsapp.sendTemplate "+1234567890" "hello_world"
ParameterTypeRequiredDescription
tostringYesRecipient phone number
templateNamestringYesTemplate name
languageCodestringNoLanguage code (default: en_US)
componentsarrayNoTemplate component parameters

sendImage

Send an image message.

Module: whatsapp | Returns: object -- Message send response.

whatsapp.sendImage "+1234567890" "https://example.com/photo.jpg" "Check this out"
ParameterTypeRequiredDescription
tostringYesRecipient phone number
imageUrlstringYesPublic URL of the image
captionstringNoOptional image caption

sendDocument

Send a document message.

Module: whatsapp | Returns: object -- Message send response.

whatsapp.sendDocument "+1234567890" "https://example.com/report.pdf" {"filename":"report.pdf"}
ParameterTypeRequiredDescription
tostringYesRecipient phone number
documentUrlstringYesPublic URL of the document
optionsobjectNoOptions: filename, caption

sendLocation

Send a location message.

Module: whatsapp | Returns: object -- Message send response.

whatsapp.sendLocation "+1234567890" 37.7749 -122.4194 {"name":"San Francisco"}
ParameterTypeRequiredDescription
tostringYesRecipient phone number
latitudenumberYesLatitude
longitudenumberYesLongitude
optionsobjectNoOptions: name, address

sendContact

Send contact card(s).

Module: whatsapp | Returns: object -- Message send response.

whatsapp.sendContact "+1234567890" [{"name":{"formatted_name":"John Doe"},"phones":[{"phone":"+0987654321"}]}]
ParameterTypeRequiredDescription
tostringYesRecipient phone number
contactsarrayYesArray of contact objects

markRead

Mark a message as read.

Module: whatsapp | Returns: object -- Status response.

whatsapp.markRead "wamid.xxx"
ParameterTypeRequiredDescription
messageIdstringYesMessage ID to mark as read

getProfile

Get the WhatsApp Business profile.

Module: whatsapp | Returns: object -- Business profile data.

whatsapp.getProfile
ParameterTypeRequiredDescription
(none)NoCall with no arguments

updateProfile

Update the WhatsApp Business profile.

Module: whatsapp | Returns: object -- Update response.

whatsapp.updateProfile {"about":"We are a business","description":"Our business description"}
ParameterTypeRequiredDescription
profileobjectYesProfile fields to update (about, address, description, email, websites, vertical)

Error Handling

All functions throw on failure. Common errors:

ErrorCause
WhatsApp API error (${res.status}): ${text}Check the error message for details
whatsapp.setCredentials requires accessToken and phoneNumberId.Check the error message for details
whatsapp.sendText requires to and message.Check the error message for details
whatsapp.sendTemplate requires to and templateName.Check the error message for details
whatsapp.sendImage requires to and imageUrl.Check the error message for details
whatsapp.sendDocument requires to and documentUrl.Check the error message for details
whatsapp.sendLocation requires to, latitude, and longitude.Check the error message for details
whatsapp.sendContact requires to and contacts array.Check the error message for details
@desc "Send text and validate result"
do
  set $result as whatsapp.sendText "+1234567890" "Hello from RobinPath!"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate Profile

Retrieve all items and loop through them.

@desc "Setup authentication"
do
  whatsapp.setCredentials $token
enddo

@desc "Get profile and iterate results"
do
  set $result as whatsapp.getProfile
  each $item in $result
    print $item
  end
enddo

2. Create a new item with sendText

Create a new resource and capture the result.

@desc "Setup authentication"
do
  whatsapp.setCredentials $token
enddo

@desc "Send text"
do
  set $result as whatsapp.sendText "+1234567890" "Hello from RobinPath!"
  print "Created: " + $result
enddo

3. Create and update workflow

Create an item and then update it.

@desc "Setup authentication"
do
  whatsapp.setCredentials $token
enddo

@desc "Send text and update profile"
do
  set $created as whatsapp.sendText "+1234567890" "Hello from RobinPath!"
  # Update the created item
  whatsapp.updateProfile {"about":"We are a business","description":"Our business description"}
enddo

4. Check before creating

List existing items and only create if needed.

@desc "Setup authentication"
do
  whatsapp.setCredentials $token
enddo

@desc "Get profile and send text"
do
  set $existing as whatsapp.getProfile
  if $existing == null
    whatsapp.sendText "+1234567890" "Hello from RobinPath!"
    print "Item created"
  else
    print "Item already exists"
  end
enddo

5. Multi-step WhatsApp workflow

Chain multiple whatsapp operations together.

@desc "Setup authentication"
do
  whatsapp.setCredentials $token
enddo

@desc "Send text, send template, and more"
do
  set $r_sendText as whatsapp.sendText "+1234567890" "Hello from RobinPath!"
  set $r_sendTemplate as whatsapp.sendTemplate "+1234567890" "hello_world"
  set $r_sendImage as whatsapp.sendImage "+1234567890" "https://example.com/photo.jpg" "Check this out"
  print "All operations complete"
enddo

6. Safe sendText with validation

Check results before proceeding.

@desc "Setup authentication"
do
  whatsapp.setCredentials $token
enddo

@desc "Send text and validate result"
do
  set $result as whatsapp.sendText "+1234567890" "Hello from RobinPath!"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • slack -- Slack module for complementary functionality
  • discord -- Discord module for complementary functionality
  • teams -- Teams module for complementary functionality
  • telegram -- Telegram module for complementary functionality
  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/whatsapp

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size5.6 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago