Back

Step by Step Guide to Building a Fireflies.ai API Integration in Ruby

Aug 14, 20246 minute read

Hey there, fellow developer! Ready to supercharge your Ruby project with some AI-powered transcription magic? Let's dive into building a Fireflies.ai API integration that'll make your colleagues wonder if you've secretly hired a team of ninjas. Buckle up!

Introduction

Fireflies.ai is like having a super-smart assistant that never sleeps, transcribing your meetings and making them searchable. Their API is the golden ticket to bringing this power into your own apps. We're about to embark on a journey to harness this API in Ruby, so get ready to impress!

Prerequisites

Before we start cooking, let's make sure we've got all the ingredients:

  • Ruby (2.6 or later)
  • httparty gem (for making HTTP requests like a boss)
  • dotenv gem (because we're responsible developers who don't hard-code API keys)
  • A Fireflies.ai API key (your magical access pass)

Setting up the project

Let's get this party started:

mkdir fireflies_integration cd fireflies_integration bundle init

Now, open that fresh Gemfile and add:

gem 'httparty' gem 'dotenv'

Run bundle install, and you're off to the races!

Authentication

First things first, let's get you authenticated:

  1. Grab your API key from the Fireflies.ai dashboard.
  2. Create a .env file in your project root:
FIREFLIES_API_KEY=your_api_key_here

Now, let's set up our base API class:

require 'httparty' require 'dotenv/load' class FirefliesAPI include HTTParty base_uri 'https://api.fireflies.ai/graphql' def initialize @options = { headers: { 'Content-Type' => 'application/json', 'Authorization' => ENV['FIREFLIES_API_KEY'] } } end end

Basic API Requests

Time to make our first request! Let's fetch some transcripts:

def get_transcripts query = '{ transcripts { id title date } }' response = self.class.post('/', body: { query: query }.to_json, headers: @options[:headers]) JSON.parse(response.body) end

Implementing Key Fireflies.ai Features

Transcription Upload

Let's add a method to upload a new transcription:

def upload_transcription(meeting_url) mutation = " mutation { uploadTranscription(input: { meetingUrl: \"#{meeting_url}\" }) { success message } } " response = self.class.post('/', body: { query: mutation }.to_json, headers: @options[:headers]) JSON.parse(response.body) end

Searching Transcripts

Now, let's add a search function:

def search_transcripts(query) mutation = " query { search(query: \"#{query}\") { id title snippets { text timestamp } } } " response = self.class.post('/', body: { query: mutation }.to_json, headers: @options[:headers]) JSON.parse(response.body) end

Error Handling and Best Practices

Always expect the unexpected:

def api_request(query) response = self.class.post('/', body: { query: query }.to_json, headers: @options[:headers]) if response.success? JSON.parse(response.body) else raise "API request failed: #{response.code} - #{response.body}" end rescue StandardError => e puts "Error: #{e.message}" nil end

Remember to respect rate limits. Fireflies.ai is powerful, but it's not invincible!

Advanced Usage: Webhooks

For real-time updates, set up a webhook:

def setup_webhook(url) mutation = " mutation { createWebhook(input: { url: \"#{url}\" events: [TRANSCRIPT_COMPLETED] }) { id url } } " api_request(mutation) end

Testing the Integration

Don't forget to test! Here's a simple RSpec example:

RSpec.describe FirefliesAPI do let(:api) { FirefliesAPI.new } it "fetches transcripts successfully" do VCR.use_cassette("transcripts") do response = api.get_transcripts expect(response["data"]["transcripts"]).to be_an(Array) end end end

Conclusion

And there you have it! You've just built a Ruby integration for Fireflies.ai that would make any developer proud. Remember, this is just scratching the surface. The Fireflies.ai API has tons more features to explore, so don't be afraid to dive deeper.

Keep coding, keep learning, and may your meetings always be perfectly transcribed! 🚀✨