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!
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!
Before we start cooking, let's make sure we've got all the ingredients:
httparty
gem (for making HTTP requests like a boss)dotenv
gem (because we're responsible developers who don't hard-code API keys)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!
First things first, let's get you authenticated:
.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
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
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
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
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!
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
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
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! 🚀✨