Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 22, 2021 07:58 pm GMT

Discord Bot for Appointment Scheduling in NodeJS

Discord has for many years been popular in the gaming community. But due to the explosion of Remote Work and Work From Home opportunities, it's strongly competing in the business world with tools like Slack, Google and Zoom.

discord scheduling bot for business
YouTube Demo: https://www.youtube.com/watch?v=e5SpHXVMlKw

You can join our Discord server and try this bot yourself: https://discord.gg/j3gd5Qk5uW

Intro

We love Discord at Spurwing, it provides all features we need for free: text and voice channels, video calls, video conferencing, screen sharing and recently the addition of stage channels. You can emulate an office experience with these channels, an ideal solution for a conservative managers.

On top of that it provides a superb API, developer community and resources for building bots and automation solutions. The business of scheduling appointments and managing calendars is a complex one, fortunately Spurwing helps simplify and streamline just that.

In this article I'll share our simple solution for scheduling appointments on Discord. The full code is available on our GitHub repository. This Discord Bot is connected to our Spurwing API for scheduling appointments and managing our calendar.

Bot summary

A discord bot is a piece of code that listens to text (or voice) data and can then respond however you program it. The easiest way to call/use a bot is to use a prefix character like ! or *. To see all available commands we can enter !help:

appointment scheduling discord bot

The first command we encounter is !days [date] which will give all available days in the month of [date]. Omitting this parameter will use the current month. You can also use keywords like today, next month, March 2021, etc. We use a great NLP Library chrono which is capable of interpreting casual text into JavaScript DateTime objects:

appointment scheduling discord bot

The second command we can use is !slots [date]. This returns a list of bookable slots on our calendar:

appointment scheduling discord bot

Do note that these slots contain a timezone offset +0200 which means GMT+2. This timezone depends the local time of the machine hosting your bot. But we can also provide a custom timezone or offset to see the times relative to your own location:

appointment scheduling discord bot timezone

If there are no bookable slots available for a certain date then you'll receive an error message:

appointment scheduling discord bot time zones

Now that we are able to find bookable slots, we can start scheduling appointments using our third command !book [slot] [@email]. You can use one of the slots as [slot] argument or provide a custom Date and Time, as long as it will evaluate to valid and bookable slot:

appointment booking discord bot

Once again if booking fails you will be given an error:

appointment booking discord bot

These three simple commands allows Discord users to schedule simple 1-on-1 appointments with you. In the next sections we'll explain how to install and configure this bot, but also how to customize it for 1-to-many appointments and incorporate multiple calendars.

Requirements

  • NodeJS v12.x or v14.x is highly recommended
  • If you don't have a Discord Bot yet, follow step 1 of this tutorial to obtain your bot's token and adding the bot to your Discord server.

Installation

  1. Clone, fork or download our repository: https://github.com/Spurwing/Chat-Bot-Integrations/
  2. Navigate to /Discord/NodeJS/ and execute npm install
  3. Copy the file config.sample.js to config.js and edit it
    • Provide your Discord Bot Token
    • Provide your Spurwing Provider Id
    • Optionally provide a Spurwing Appointment Type Id
  4. Run the bot: node index.js
    • Optionally use PM2 or nodemon to keep the bot running 24/7

Upon successful connection you should see a message like:
discord bot scheduling appointments

If you didn't provide an Appointment Type Id, the code will fetch a random one from your Spurwing account. Each appointment type has an associated duration (15min, 30min, 45min, ...). Our API uses it to generate bookable slots.

Developers

This bot is merely a basic implementation for demo purposes. We can extend it with more advanced features to facilitate Calendar Management, Group Bookings, Reminders, Sending Emails, Voice Commands and more.

discord bot

State Management

The Spurwing Provider ID (PID) represents an individual calendar. You can extend the bot to keep a mapping of Discord Members and their PIDs. If your Spurwing account has Organizational privileges then you can create multiple accounts (and thus PIDs) for all your members. Each calendar can also be two-way synced with any third-party email provided (Gmail, Outlook, Apple).

team scheduling api

Group Bookings

Our demo bot only allows for 1-on-1 bookings, hence the single [@email] argument for the !book command. You can extend that command to allow a list of email addresses.

Alternatively you can create a mapping of Discord Members and their email addresses. Now instead of providing their emails explicitly to the command you can use the @username notation by Discord.

Reminders

To incorporate automated reminders, either as public announcements or private messages, you make the bot poll for all calendar events (every minute or so). And based on your preferences make it send reminders to all participants.

discord bot reminder

Sending Emails

We already have a Spurwing Library for sending emails using the SMTP protocol. Our iCalendar Library Repository contains all the logic you need inside index.js, in particular the sendMail function which you can re-use here.

Voice Commands

The thing I love about Discord the most are its voice channels. It's just a virtual place you can join and talk to everyone inside the channel. No annoying meeting links needed to instantly hop on a call with someone.

A Discord Bot can also join a voice channel and listen to all speakers individually (but can also send audio data). One of my personal open-source projects DiscordEarsBot uses NLP and Machine Learning to transcribe and interpret what is being said. This solution is pretty accurate and supports 32 of languages. You can use that solution for adding Voice Commands or generated suggestions based on what is being said during a conversation:

You: maybe we should meet again next week?Bot: Would you like to schedule for next week this time?

Conclusion

Another cool UX improvement to the !book [slot] ... command is to make return a few bookable slots if it fails to schedule for the [slot] you provided.

Discord Bots are amazing tools that can help us automate tasks and be more productive at our daily business. If you enjoy our content, make sure to give us a star on GitHub and follow us for more. Visit Spurwing and schedule a free demo today. Have a great day!


Original Link: https://dev.to/spurwing/discord-bot-for-appointment-scheduling-in-nodejs-5fd

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To