Transforming Teaching with Teachingo - Update #5
Tags: twiliohackathon, node, javascript, twilio
Published: 2020-04-28 21:40:57

_This is an update on our #TwilioHackathon project progress - you can see the original post here: {% link https://dev.to/chloemcateer3/transforming-teaching-with-teachingo-4lc5 %}_

---

## Integrate all the things! 💭

Our focus for the Twilio integration was the Video API, but we also wanted to see if we could use another service if we found the time.

Reading up on the documentation, it was clear to see that the Twilio Video API was incredibly simple to use and get up and running. The documentation is fantastic and the concepts are really well explained.

We knew we had to to build an endpoint out on our Node.js service in order to facilitate distributing access tokens and doing this was easy with the JS SDK:

```js
        // Format will be lessonId-userId-firstName-lastName
        const identity = `${lessonId}-${id}-${firstName}-${lastName}`;

        // Combination of class name && lessonID to make up the roomName
        // Format will be lessonId-className
        const roomName = `${lessonId}-${className}`;

        const token = getAccessToken();

        token.identity = identity;
        const videoGrant = getVideoGrant(roomName);
        token.addGrant(videoGrant);

        console.log(
            `Issued Twilio Video token for ${identity} in room ${roomName}`
        );

        res.send(token.toJwt());
```

We had simply abstracted the Twilio SDK logic out to another [service](https://github.com/pmc-a/teachingo-api/blob/master/src/twilio/index.js), but it essentially just creates a handy wrapper around the SDK and separated the concerns - easier to test, am I right?!

![Brooklyn 99 - Jake saying "Oooh"](https://media.giphy.com/media/BZhrhoxl6CFa98vTCZ/giphy.gif)

This was our nifty endpoint to grant a Twilio access token that allows the client to join the specific room that it is made for!

## But wait, there's more?! 📲

We had gotten the taste of the Twilio services and what they could offer, so we wanted to investigate what else we could potentially integrate with.

The one thing that Twilio is almost industry standard for is the SMS functionality. We decided to give it a whirl and implement a feature that allowed the teacher to contact the absent students to check up and ensure they were ok as well as a prompt to get caught up when they get the time.

We quickly jumped onto the Twilio docs and followed along. In no time, we had bought and reserved a mobile number to facilitate our SMS service!

![Twilio Active Numbers Interface](https://i.imgur.com/9XvjKKn.png)

All that was left was for us to integrate into our existing system, which meant another endpoint on our Node.js service to allow our React web application to invoke it.

And surpire surprise, Twilio SDK made it _incredibly_ easy once again:

```js
const contactClient = require('twilio')(twilioAccountSid, twilioAuthToken);

const sendMessageToStudent = async (className, mobileNumber, res) => {
    contactClient.messages
        .create({
            body: `You missed today's ${className.name} lesson, please make sure you catch up on content and attend the next one! If you are not able to attend for any reason please let me know!`,
            from: twilioMobileNumber,
            to: mobileNumber,
        })
        .then((message) => {
            console.log(message.sid);
            res.status(200).json('ok');
        })
        .catch((error) => {
            console.log(error);
            res.status(500).json('An error occurred contacting student');
        });
};
```

And that was it! Awesome, right? Don't believe it was this easy? Neither did I..

![Brooklyn 99 - Charles cool](https://media.giphy.com/media/2kJIUDgdLVum9oaLSK/giphy.gif)

But it really was!

![Screenshot of messages application on iOS with automated SMS conversation from Twilio mobile number](https://i.imgur.com/R96AQct.png)

This is our last progress update, we hope you have enjoyed following along with some of our trials and tribulations of software development!

Be sure to check out our final submission and project over here:

{% link https://dev.to/chloemcateer3/transforming-teaching-with-teachingo-4lc5 %}

---

Stay tuned for more progress updates from [Chloe](https://dev.to/chloemcateer3) and myself!