Prerequisites
-
WeWeb Project: Have an existing WeWeb project set up
-
Despia Account: Create a free Despia account at despia.com
-
Despia Project: Create and link a Despia project with your WeWeb staging or production domain
Overview
The integration allows your WeWeb application to:
-
Request permission to access device contacts
-
Read all contacts from the user's device
-
Import contact data (names and phone numbers) into your WeWeb application
-
Display contacts in a list or send them to your backend
Set Up Contact Permission Request
First, you need to request permission from users to access their contacts.
1.1 Add Permission Button
-
In your WeWeb editor, add a button to your page
-
Name it "Allow Contacts"
-
This can be part of your onboarding flow or settings page
1.2 Create Permission Workflow
-
Click on the button and add a new workflow
-
Name the workflow:
ask for contacts permission
-
Add a "Custom JavaScript" action
-
Name the action:
Despia SDK Contact Permission
1.3 Add Permission Code
In the code editor, paste the following:
window.despia = "requestcontactpermission://"
This deep link triggers the native permission dialog on the user's device.
Create Contact Storage Variable
-
Go to your WeWeb variables
-
Create a new variable named
Contacts
-
Set the type to
Array
-
Initially, add a sample value for easier development:
[ { "name": "John Doe", "number": "+1234567890" } ]
-
Once development is complete, clear this to an empty array
[]
Set Up Contact Reading Functionality
3.1 Add Fetch Contacts Button
-
Add another button below the permission button
-
Name it "Fetch Contacts"
3.2 Create Read Contacts Workflow
-
Click on the button and add a new workflow
-
Name the workflow:
read contacts
-
Set the trigger to "On click"
3.3 Add Contact Reading Code
-
Add a "Custom JavaScript" action
-
Name it:
Despia SDK Read Contacts
-
In the code editor, paste the following asynchronous handler:
window.despia = "readcontacts://"
const variable = "contacts";
return new Promise((resolve, reject) => {
const startTime = Date.now();
const timeout = 5000;
function checkVariable() {
if (window[variable] !== undefined) {
resolve(window[variable]);
} else if (Date.now() - startTime < timeout) {
setTimeout(checkVariable, 100);
} else {
reject(`Timeout: ${variable} not available after ${timeout}ms`);
}
}
checkVariable();
});
Format Contact Data
Despia returns contacts in a specific format that needs to be converted to a JSON array for WeWeb.
4.1 Add Formatting Function
-
In your workflow, add another "Custom JavaScript" action after the read contacts action
-
Name it:
Format Despia Contact JSON
-
Add the following formatting code:
const input = context.workflow['CONTEXT-ID-FROM-ABOVE-STEP'].result;
const result = Object.entries(input).map(([name, numbers]) => ({
name,
number: numbers[0]
}));
return result;
4.2 Update Contacts Variable
-
Add a "Change variable value" action
-
Name it:
Update Contacts Variable
-
Select the
contacts
variable -
Set it to "Replace all items with"
-
Use the result from the formatting action
Display Contacts in a List
5.1 Add List Component
-
Add a List component to your page
-
The list should have text elements for name and phone number
5.2 Configure List Binding
-
Select the list item
-
Go to "Repeat" settings
-
Bind the items to your
contacts
variable -
For the name text element, bind to
item.name
-
For the phone number element, bind to
item.number
Testing Your Implementation
6.1 Publish to WeWeb
-
Click "Publish" in WeWeb
-
Choose "Publish to WeWeb subdomain" or your custom domain
-
Add a comment for version tracking
6.2 Test on Device
-
Open your Despia app on your mobile device
-
Navigate to your WeWeb application
-
Click "Allow Contacts" (first time only)
-
Click "Fetch Contacts"
-
Select contacts to share (iOS) or grant permission (Android)
-
Your contacts should appear in the list
Advanced Features
Sending Contacts to Backend
Once contacts are in your WeWeb variable, you can:
-
Send them to Xano
-
Store in Supabase
-
Process with any backend service
Error Handling
Add error handling to your workflows:
try {
// Your contact reading code
} catch (error) {
console.error('Failed to read contacts:', error);
// Show user-friendly error message
}
Permission Status Check
You can check if permission was granted by verifying if the contacts variable is populated after the request.
Best Practices
-
Onboarding Integration: Include contact permission in your app's onboarding flow
-
Clear Communication: Explain why you need contact access before requesting permission
-
Privacy: Only request contacts when necessary and handle data securely
-
Empty States: Design for cases where users deny permission or have no contacts
-
Performance: For large contact lists, consider pagination or lazy loading
Troubleshooting
Contacts Not Loading
-
Ensure permission was granted
-
Check that the Despia handler is properly initialized
-
Verify your WeWeb domain is correctly linked in Despia
Format Issues
-
Make sure the formatting function is correctly parsing Despia's response
-
Check the browser console for any JavaScript errors
Permission Denied
-
You cannot re-request permission programmatically on iOS
-
Users must go to device settings to re-enable permission
For additional support or questions, please contact our support team at support@despia.com