Installation
This guide will help you install and set up meta-cloud-api in your project.
System Requirements
Before installing, ensure your system meets these requirements:
- Node.js: >= 18.0.0
- Package Manager: npm, yarn, or pnpm
- TypeScript: >= 5.0.0 (recommended)
Install the Package
Choose your preferred package manager:
pnpm add meta-cloud-apinpm install meta-cloud-apiyarn add meta-cloud-apiTypeScript Configuration
If you’re using TypeScript, ensure your tsconfig.json includes:
{ "compilerOptions": { "target": "ES2022", "module": "ES2020", "moduleResolution": "node", "esModuleInterop": true, "strict": true }}Environment Variables
Create a .env file in your project root:
# RequiredCLOUD_API_ACCESS_TOKEN=your_access_tokenWA_PHONE_NUMBER_ID=your_phone_number_id
# OptionalWA_BUSINESS_ACCOUNT_ID=your_business_account_idWEBHOOK_VERIFICATION_TOKEN=your_webhook_tokenGetting Your Credentials
To obtain these credentials:
-
Access Token:
- Go to Meta Developer Portal
- Create a new app or select an existing one
- Navigate to WhatsApp > API Setup
- Copy your temporary or permanent access token
-
Phone Number ID:
- In the WhatsApp API Setup page
- Find your phone number under “Phone numbers”
- Copy the Phone Number ID
-
Business Account ID (optional):
- In Meta Business Suite
- Go to Business Settings
- Copy your WhatsApp Business Account ID
-
Webhook Verification Token (for webhooks):
- Create a random secure string
- Use this when setting up webhooks in Meta Developer Portal
Verify Installation
Create a test file to verify the installation:
import WhatsApp from 'meta-cloud-api';
const client = new WhatsApp({ accessToken: process.env.CLOUD_API_ACCESS_TOKEN!, phoneNumberId: Number(process.env.WA_PHONE_NUMBER_ID), businessAcctId: process.env.WA_BUSINESS_ACCOUNT_ID,});
console.log('✓ meta-cloud-api installed successfully!');Run the test:
tsx test.ts# ornode --loader ts-node/esm test.tsIf you see the success message, you’re ready to start using meta-cloud-api!
Troubleshooting
Module not found error
If you get a “Cannot find module ‘meta-cloud-api’” error:
- Ensure the package is installed:
pnpm list meta-cloud-api - Clear your node_modules and reinstall:
rm -rf node_modules && pnpm install - Check your import statement matches the package name exactly
TypeScript errors
If you encounter TypeScript errors:
- Ensure you’re using TypeScript >= 5.0.0
- Enable
esModuleInteropin tsconfig.json - Check that
moduleResolutionis set to “node”
Environment variable issues
If environment variables aren’t loading:
- Install dotenv:
pnpm add dotenv - Load at app entry:
import 'dotenv/config'; - Verify .env file is in the correct location
Support
Need help? Check out: