Back

Quick Guide to Realtime Data in Fireflies.ai without Webhooks

Aug 14, 20246 minute read

Hey there, fellow JavaScript aficionados! Ready to dive into the world of real-time data fetching from Fireflies.ai without the hassle of webhooks? Let's get our hands dirty with some good old polling action!

Why Polling?

Sure, webhooks are cool, but sometimes you just want to keep things simple. Polling gives you more control and can be easier to implement, especially for user-facing integrations. Plus, it's a great fallback when webhooks aren't available or reliable.

Setting the Stage

First things first, let's get our environment ready. You'll need:

npm install axios dotenv

And don't forget to set up your .env file with your Fireflies.ai API key:

FIREFLIES_API_KEY=your_api_key_here

The Polling Mechanism

Alright, let's build our polling function. Here's a basic structure to get us started:

require('dotenv').config(); const axios = require('axios'); async function pollFireflies() { try { // API request logic here } catch (error) { console.error('Polling error:', error); } } setInterval(pollFireflies, 60000); // Poll every minute

Fetching the Good Stuff

Now, let's actually fetch some data. We'll use the /v2/transcripts endpoint for this example:

async function pollFireflies() { try { const response = await axios.get('https://api.fireflies.ai/graphql', { headers: { Authorization: `Bearer ${process.env.FIREFLIES_API_KEY}`, }, params: { query: ` query { transcripts(last: 10) { nodes { id title created_at } } } `, }, }); // Process the data const transcripts = response.data.data.transcripts.nodes; updateLocalStore(transcripts); updateUI(transcripts); } catch (error) { console.error('Polling error:', error); } }

Handling the Data

Once we've got our data, we need to do something with it:

function updateLocalStore(transcripts) { // Update your local data store (e.g., Redux, local storage) } function updateUI(transcripts) { // Update your UI components }

Optimizing for the Win

Let's make our polling smarter with exponential backoff:

let pollInterval = 60000; // Start with 1 minute const maxInterval = 300000; // Max 5 minutes async function pollWithBackoff() { try { await pollFireflies(); pollInterval = 60000; // Reset on success } catch (error) { console.error('Polling error:', error); pollInterval = Math.min(pollInterval * 2, maxInterval); } finally { setTimeout(pollWithBackoff, pollInterval); } } pollWithBackoff();

Putting It All Together

Here's a complete example that ties everything together:

require('dotenv').config(); const axios = require('axios'); let pollInterval = 60000; const maxInterval = 300000; async function pollFireflies() { try { const response = await axios.get('https://api.fireflies.ai/graphql', { headers: { Authorization: `Bearer ${process.env.FIREFLIES_API_KEY}`, }, params: { query: ` query { transcripts(last: 10) { nodes { id title created_at } } } `, }, }); const transcripts = response.data.data.transcripts.nodes; updateLocalStore(transcripts); updateUI(transcripts); } catch (error) { throw error; } } function updateLocalStore(transcripts) { // Update your local data store console.log('Updating local store with', transcripts.length, 'transcripts'); } function updateUI(transcripts) { // Update your UI components console.log('Updating UI with latest transcripts'); } async function pollWithBackoff() { try { await pollFireflies(); pollInterval = 60000; // Reset on success } catch (error) { console.error('Polling error:', error); pollInterval = Math.min(pollInterval * 2, maxInterval); } finally { setTimeout(pollWithBackoff, pollInterval); } } pollWithBackoff();

Wrapping Up

And there you have it! A slick, efficient way to fetch real-time data from Fireflies.ai using polling. Remember to keep an eye on your API usage and adjust your polling frequency accordingly.

Happy coding, and may your data always be fresh! 🚀