This tutorial will walk through how to use Verida API's to access user data, with a focus on accessing Telegram data.
If you haven't already, register a Verida Account, sign into the Developer Console and obtain an Auth token so you can make API requests.
Once you have an auth token, you must include it in your API requests.
Here are some examples of API requests to the AI agent endpoint.
Command line (via curl):
curl -X POST -H "Authorization: Bearer <authToken>" "https://api.verida.ai/api/rest/v1/llm/agent" \
-H "Content-Type: application/json" \
-d '{}'
Node.js:
const axios = require('axios');
axios({
method: 'POST',
url: 'https://api.verida.ai/api/rest/v1/llm/agent',
data: {},
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer <authToken>'
}
})
.then(res => {
console.log(res.data)
})
.catch(err => {
console.error(err)
})
Useful resources:
When a user connects their Telegram account, their groups and messages are syncronized and the data is normalized into common data types. See Data Types to learn more.
Telegram populates two data schemas:
We need to query these schemas using the 4. Query a Datastore API endpoint.
Let's start with an example to fetch all the Telegram chat groups a user is in. We need to make an API request to the /ds/query
endpoint (https://api.verida.ai/api/rest/v1/ds/query/
).
This endpoint takes a schema, in our case we want the social chat group schema (https://common.schemas.verida.io/social/chat/group/v0.1.0/schema.json), however we don't send the actual schema URL, we base64 encoded it.
Node.js example:
const axios = require('axios');
const schemaUrl = 'https://common.schemas.verida.io/social/chat/group/v0.1.0/schema.json';
const schemaUrlEncoded = bvoa(schemaUrl);
axios({
method: 'POST',
url: `https://api.verida.ai/api/rest/v1/ds/query/${schemaUrlEncoded}`,
data: {
"options": {
"sort": [
{
"_id": "desc"
}
],
"limit": 20
}
},
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer <authToken>'
}
})
.then(res => {
console.log(res.data)
})
.catch(err => {
console.error(err)
})
View the example JSON response of a chat group.
We can update the query
to restrict to only include results from:
{
"sourceApplication": "https://telegram.com",
"groupId": "telegram-456049390--579961374",
"type": "send",
"sentAt": {
"$gte": "2025-01-01"
}
}
You may want to make requests such as:
It is possible to use the /query
API endpoint and loop through all the pages of data to count, but that is highly inefficient.
This functionality will be coming very shortly with a new /count
endpoint.
You may want to learn more about a user's profile on Telegram, for example:
This data is currently syncronized, but not available via the API.
This functionality will be coming very shortly with a new /profile
endpoint
Verida empowers developers and users alike with secure, user-owned data storage, identity management, and a suite of powerful APIs
Verida AI Documentation