Hey there, fellow developer! Ready to supercharge your app with some serious calling capabilities? Look no further than the JustCall API. With the @justcall/justcall-dialer-sdk
package, you'll be making and managing calls like a pro in no time. Let's dive in and get your integration up and running!
Before we jump into the code, make sure you've got:
First things first, let's get our project set up:
mkdir justcall-integration cd justcall-integration npm init -y npm install @justcall/justcall-dialer-sdk
Boom! You're ready to roll.
Now, let's get you authenticated. Grab your API key and secret from your JustCall dashboard, and let's put them to work:
const JustCall = require('@justcall/justcall-dialer-sdk'); const client = new JustCall({ apiKey: 'YOUR_API_KEY', apiSecret: 'YOUR_API_SECRET' });
Pro tip: In a real-world scenario, you'd want to use environment variables for these credentials. Security first, folks!
Let's make sure everything's working with a quick test call:
client.getUser() .then(user => console.log('User details:', user)) .catch(error => console.error('Oops!', error));
If you see your user details in the console, you're golden!
Time to make some noise:
client.makeCall({ to: '+1234567890', from: 'YOUR_JUSTCALL_NUMBER' }) .then(call => console.log('Call initiated:', call.id)) .catch(error => console.error('Call failed:', error));
Set up a webhook to catch those incoming calls:
const express = require('express'); const app = express(); app.post('/incoming-call', (req, res) => { const call = req.body; console.log('Incoming call from:', call.from); // Handle the call as needed res.sendStatus(200); }); app.listen(3000, () => console.log('Webhook server running'));
Keep tabs on your calls:
client.getCallLogs({ limit: 10 }) .then(logs => console.log('Recent calls:', logs)) .catch(error => console.error('Failed to fetch logs:', error));
Record calls like a boss:
client.startRecording(callId) .then(() => console.log('Recording started')) .catch(error => console.error('Recording failed to start:', error));
Because sometimes you just need to text:
client.sendSMS({ to: '+1234567890', from: 'YOUR_JUSTCALL_NUMBER', body: 'Hello from JustCall!' }) .then(message => console.log('SMS sent:', message.id)) .catch(error => console.error('SMS failed:', error));
Stay in the loop with real-time updates:
app.post('/call-status', (req, res) => { const status = req.body; console.log('Call status update:', status); // Handle the status update res.sendStatus(200); });
Always expect the unexpected:
client.makeCall(/* ... */) .catch(error => { if (error.code === 'RATE_LIMIT_EXCEEDED') { console.log('Whoa there! Slow down a bit.'); } else { console.error('Something went wrong:', error); } });
And remember, be kind to the API. Implement proper rate limiting to avoid any hiccups.
Test, test, and test again:
const assert = require('assert'); describe('JustCall API', () => { it('should fetch user details', async () => { const user = await client.getUser(); assert(user.id, 'User ID should be present'); }); });
When things go sideways, console.log
is your best friend. Sprinkle it liberally!
When you're ready to go live:
And there you have it! You're now armed and dangerous with JustCall API integration skills. Remember, the docs are your friend, so don't be shy about diving deeper.
Keep coding, keep calling, and most importantly, keep being awesome!