tutorial programming technical tools Apr 28, 2022
How to start a Zoom Meeting from Rails ?
On a recent project at Azuki, we have been using the Zoom API and we thought that it would be a great idea to share how we did it. In this very simple tutorial, I am going to show you how to automatically create a zoom link automatically whenever you create a meeting (or a reunion, or even a pow-wow).
First thing first, who says Rails says gem ! and of course someone created a wonderful gem that we are going to use. Zoom_rb .
So we’re going to add the gem to our gemfile.rb
gem 'zoom_rb'
and then run bundle install
Follow this link : https://marketplace.zoom.us/develop/create and click on ‘create’ in the JWT box.
Once you have your API key and secret, copy and paste them into your .env file (or whatever environment you are using) . Let’s create an initializer file that will load up with our app.
So into config/initializers, you can create a file called Zoom.rb
and set the keys :
Zoom.configure do |c|
c.api_key = ENV['ZOOM_API_KEY']
c.api_secret = ENV['ZOOM_API_SECRET']`
end
In your terminal, go in your console (type : rails c
)
zoom_client = Zoom.new
zoom_client.user_list
This will return you with a hash of informations, just grab the “id” and copy and paste it into your .env file as ZOOM_USER_ID
To simplify here let’s imagine here you have a Meeting model (meeting.rb
). first thing you want to do is to run a migration to add a Zoom link to your model.
rails g migration AddZoomLinkToMeetings zoom_link:string
don’t forget to rails db:migrate
Inside our model, we are going to create two methods. The first one is going to create the meeting on Zoom and fetch the URL for you.
def create_zoom_meeting(topic)
zoom_client = Zoom.new
response = zoom_client.meeting_create(topic: topic, user_id: ENV['ZOOM_USER_ID'])
response['join_url']
end
The second method will save the newly created zoom link in your database
def save_zoom_link(meeting_topic)
return if zoom_link.present?
_zoom_link = create_zoom_meeting(meeting_topic)
update(zoom_link: _zoom_link)
end
Now that we have our methods, we need to call them.
What we want is to have a link when we create a meeting. So let’s head to our meetings_controller.rb
Now let’s call the methods in our create actions
def create
@meeting = Meeting.new(meeting_params)
@meeting.save_zoom_link(@meeting.name)
@meeting.save
redirect_to meeting_path(@meeting)
end
You can set the meeting_topic to whatever you want.
Let’s double check in the console
rails c
Meeting.last.zoom_link
If it worked you should see a zoom link for your meeting !
I hope this tutorial was useful, the process is quite simple but some bits can be a bit tricky.
Have fun !
Our little BONUS for enthusiast reader :
You can set recurrent meeting if you want and allow some extra options. Here’s an example :
zoom_client.meeting_create(
topic: topic,
type: 8,
user_id: zoom_account.user_id,
start_time: Time.now.iso8601,
duration: 120,
recurrence: {
type: 1,
end_times: 5,},
settings: {
host_video: true,
participant_video: true,
mute_upon_entry: true,
}
)
Photo by iyus sugiharto on Unsplash