Created
January 3, 2023 21:13
-
-
Save ryanb/b53a0010455cca4259a913f356f72a00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This should be triggered through a cron job at 6:15 PM on week days. | |
# Example cron: 15 18 * * 1,2,3,4,5 cd ~/code/jury_duty && ~/.rbenv/shims/ruby call.rb >> ~/code/jury_duty/call-log.txt 2>&1 | |
# It uses Twilio to make a call based on TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, and TWILIO_PHONE. | |
# It calls the JURY_PHONE, transcribes it, looks for JURER_NUMBER and texts the result to PERSONAL_PHONE. | |
require "rubygems" | |
require "bundler/setup" | |
Bundler.require(:default) | |
Dotenv.load | |
twilio = Twilio::REST::Client.new(ENV["TWILIO_ACCOUNT_SID"], ENV["TWILIO_AUTH_TOKEN"]) | |
call = twilio.calls.create( | |
twiml: '<Response><Record timeout="10" transcribe="true"/></Response>', | |
to: ENV["JURY_PHONE"], | |
from: ENV["TWILIO_PHONE"], | |
) | |
puts "Calling..." | |
puts "Call ID: #{call.sid}" | |
sleep 30 | |
puts "Hanging up" | |
call.update(status: "completed") | |
puts "Waiting for transcript..." | |
sleep 30 | |
transcription = nil | |
hour_ago = Time.now - (60 * 5) | |
8.times do | |
transcriptions = twilio.transcriptions.list(limit: 5) | |
transcription = transcriptions.first | |
if transcription.date_created < hour_ago | |
puts "Still waiting on transcript..." | |
sleep 30 | |
else | |
break | |
end | |
end | |
puts transcription.date_created | |
puts transcription.transcription_text | |
if transcription.transcription_text.include? ENV["JURER_NUMBER"] | |
puts "Found #{ENV["JURER_NUMBER"]} in transcript!" | |
twilio.messages.create( | |
from: ENV["TWILIO_PHONE"], | |
to: ENV["PERSONAL_PHONE"], | |
body: "Your number #{ENV["JURER_NUMBER"]} has been called! #{transcription.transcription_text}" | |
) | |
else | |
puts "Could not find #{ENV["JURER_NUMBER"]} in transcript." | |
twilio.messages.create( | |
from: ENV["TWILIO_PHONE"], | |
to: ENV["PERSONAL_PHONE"], | |
body: "No jury duty yet. #{transcription.date_created.strftime('%b %d')} #{transcription.transcription_text}" | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment