There are (probably?) a few ways to go about this but I've found a way that works, though it's not the most streamlined solution.
First of all, here are the Meetup API Docs.
The docs include a "Try it in the console" link for each type of request so that you can see what the structure of the returned payload will be.
When sending a GET request for upcoming events to Meetup's API, only event hosts/organizers within the freeCodeCamp-Nashville Meetup group have access to the "announced" property. However, when an event is announced, all members of the group will receive a notification of type event_announce so we can use the GET Meetup Notifications endpoint to check for event announcements.
Getting access to a user's Meetup notifications requires that user's permission via OAuth2 authorization. I have already set up our Discord bot as an "OAuth Consumer" with Meetup. To get an access token, I'd recommend using something like Postman to send the request with our OAuth credentials which will give you back an access token. Once you have gotten this far, please ping me on Discord in a private message and I will pass along the credentials. Please keep them in a local .env file (that is properly ignored in your .gitignore file) to keep them secret. If you need help with this process, let me know.
Once you have an access token, you can fire off requests to Meetup's API to get the user's notifications by including the access token as an authorization bearer in the header of the request, like so:
To see whether an event needs announcing in the Discord, you will want to schedule a job in bot.js inside of the bot.on('ready', () => {}) function to run every 5 minutes that checks for new event announcements. Using the function above to query Meetup's API for the user's notifications, the notifications variable will contain an array of all of that user's notifications.
Once you have that array, you'll want to filter through the notifications to find any that are "kind": "event_announce" and that match our group's ID "target.group_id": "22817838" <-- this is our actual group ID, so you can use this for your filtering. Once you've done that you should have a new array that consists only of event announcements for the freeCodeCamp-Nashville group. You can then map over this array and check whether the event needs to be sent to Discord.
Every notification has a property of updated which gives the Unix timecode for when it was sent. By comparing this time to the current time, you will want to send the events to Discord for which the time difference is less than 5 minutes (since you are checking every 5 minutes) meaning that the event was announced since the last check. If it has been greater than 5 minutes, you can safely ignore those event announcements since they would have already been announced. This can be done rather simply by declaring a new variable containing the current Unix timecode const now = new Date.now(); and comparing it to the updated time code in an if statement: if (now - event.updated < 300000)
Inside of your if block, you will now have an event announcement notification for the freeCodeCamp-Nashville group that has been sent within the last five minutes. Use the Meetup API to get the details for that specific event: https://api.meetup.com/freeCodeCamp-Nashville/events/${event.target.event_id} and store that event in a variable, ex: eventDetails. If the event is a mentor night event (eventDetails.name === 'Mentor Night') then send it to the mn-announcements channel. Otherwise, it's likely to be a monthly meetup, so you can probably just send it to the MONTHLY-MEETUP => announcements channel.
There are (probably?) a few ways to go about this but I've found a way that works, though it's not the most streamlined solution.
First of all, here are the Meetup API Docs. The docs include a "Try it in the console" link for each type of request so that you can see what the structure of the returned payload will be.
When sending a GET request for upcoming events to Meetup's API, only event hosts/organizers within the freeCodeCamp-Nashville Meetup group have access to the "announced" property. However, when an event is announced, all members of the group will receive a notification of type
event_announce
so we can use the GET Meetup Notifications endpoint to check for event announcements.Getting access to a user's Meetup notifications requires that user's permission via OAuth2 authorization. I have already set up our Discord bot as an "OAuth Consumer" with Meetup. To get an access token, I'd recommend using something like Postman to send the request with our OAuth credentials which will give you back an access token. Once you have gotten this far, please ping me on Discord in a private message and I will pass along the credentials. Please keep them in a local .env file (that is properly ignored in your .gitignore file) to keep them secret. If you need help with this process, let me know.
Once you have an access token, you can fire off requests to Meetup's API to get the user's notifications by including the access token as an authorization bearer in the header of the request, like so:
To see whether an event needs announcing in the Discord, you will want to schedule a job in
bot.js
inside of thebot.on('ready', () => {})
function to run every 5 minutes that checks for new event announcements. Using the function above to query Meetup's API for the user's notifications, thenotifications
variable will contain an array of all of that user's notifications.Once you have that array, you'll want to
filter
through the notifications to find any that are"kind": "event_announce"
and that match our group's ID"target.group_id": "22817838"
<-- this is our actual group ID, so you can use this for your filtering. Once you've done that you should have a new array that consists only of event announcements for the freeCodeCamp-Nashville group. You can thenmap
over this array and check whether the event needs to be sent to Discord.Every notification has a property of
updated
which gives the Unix timecode for when it was sent. By comparing this time to the current time, you will want to send the events to Discord for which the time difference is less than 5 minutes (since you are checking every 5 minutes) meaning that the event was announced since the last check. If it has been greater than 5 minutes, you can safely ignore those event announcements since they would have already been announced. This can be done rather simply by declaring a new variable containing the current Unix timecodeconst now = new Date.now();
and comparing it to theupdated
time code in anif
statement:if (now - event.updated < 300000)
Inside of your
if
block, you will now have an event announcement notification for the freeCodeCamp-Nashville group that has been sent within the last five minutes. Use the Meetup API to get the details for that specific event:https://api.meetup.com/freeCodeCamp-Nashville/events/${event.target.event_id}
and store that event in a variable, ex:eventDetails
. If the event is a mentor night event (eventDetails.name === 'Mentor Night'
) then send it to themn-announcements
channel. Otherwise, it's likely to be a monthly meetup, so you can probably just send it to theMONTHLY-MEETUP => announcements
channel.You're done. Celebrate with cheese and wine.