Thank you for joining us again for part two of this series. As a recap, in the last section we talked about webhooks, what are they, why use them and gave some real life examples.
I have decided to use a webhook-only app for this example because the setup is simple, and event subscriptions are all we'll need. You can also use webhooks with OAuth apps and the Server-to-Server OAuth apps if you need to make API requests.
Create a webhook-only app in the Zoom App Marketplace:
- Log in to your Zoom account and head to the Zoom App Marketplace to start.
- Click the dropdown that says Develop and then click Build App:
- Make sure to click Create under the tile that says Webhook Only and give your app a name.
Fill up the required information and once that's done, head to the Feature tab and make sure to enable event subscriptions. Give your event subscription a name and in the event notification endpoint URL, make sure to add your ngrok URL. We need to expose the local server to the internet to accept post requests from Zoom.
To get an event notification endpoint URL for this guide, run the following command:
$ ngrok http 3000
Copy the ngrok https url displayed in terminal and include /webhook path, it should look like this:
https://exampleurl.ngrok.io/webhook
Click on Add events. For this guide, we will only add "Meeting has been created" and "Meeting has been deleted" and click done.
Lastly, click Continue so you can activate your app.
Set up the sample app
Pre-requisites:
- Node JS
- Ngrok
- PostgreSQL
- Zoom Account
- Webhook-only app credentials
Now that your webhook-only app is created and activated in the Zoom Marketplace, it is time to run the sample app in your local environment.
Setup and install
First, clone the git repository found here:
git clone https://github.com/zoom/webhook-to-postgres
Use NPM to install dependencies:
$npm install
Open the .env file in your text editor and enter the following information from the feature section that you just configured:
# Zoom Secret token from your Webhook only app
ZOOM_WEBHOOK_SECRET_TOKEN=
Create our Database
You can skip these steps if you already have Postgres installed in your local environment. If not, follow along to install pg and create a table in your database.
- If you are using Windows, download a Windows installer of PostgreSQL, or you can use this PostgreSQL Portable Copy.
- If you are using a Mac and you have Homebrew installed on your computer, open up the terminal and install PostgreSQL with brew:
brew install postgresql
After the installation is complete, we'll want to get PostgreSQL up and running, which we can do with services start.
brew services start postgresql
With PostgreSQL now installed, we will connect to the default Postgres database running
psql postgres
We are now inside psql in the Postgres database. You will see the prompt ends with an # to denote that we are logged in as the superuser, or root (postgres=#).
Commands within psql start with a backslash. To test this, we can check what database, user, and port we have connected to using the \conninfo command
postgres=# \conninfo
Creating a role in Postgres
We are going to create a role called "me" and give it a password of "password":
postgres=# CREATE ROLE me WITH LOGIN PASSWORD 'password';
And we want "me" to be able to create a database:
postgres=# ALTER ROLE me CREATEDB;
Now, we will create a database for the "me" user. Exit from the default session with \q for quit and now we will connect Postgres with "me"
psql -d postgres -U me
We can create a database with the SQL command as follows:
CREATE DATABASE zoomwebhooks;
Connect to the new database
\c zoomwebhooks
You are now connected to database "zoomwebhooks" as a user "me".
Creating a table in Postgres
Finally, in the psql command prompt, we will create a table called events with four fields, two VARCHAR types, one BIGINT type, and an auto-incrementing PRIMARY KEY ID:
CREATE TABLE events (
ID SERIAL PRIMARY KEY,
name VARCHAR(30),
accountid VARCHAR(30),
meetingid BIGINT
);
We have finished with all our PostgreSQL tasks, and make sure to add the credentials in your .env file. Now it is time to get our app up and running!
# PostgreSQL credentials and information
PORT=
PG_USER=
PG_HOST=
PG_DATABASE=
PG_PASSWORD=
PG_PORT=
Start the app
It is time to run the app
$npm run start
While your app is running on port 3000, go to Zoom here and create a meeting or delete an existing meeting in your account.
Once you do this, you will see the event printed in your console and a new instance created in your Postgres database.
You can add as many events as you want, and they all will be stored in your database.
Thank you for follow along and happy coding 😀!
Top comments (0)