Facebook messenger bot that displays latest IT jobs in Goa, India
Tags: showdev, bot, javascript, beginners
Published: 2018-09-03 17:27:56

---
title: Facebook messenger bot that displays latest IT jobs in Goa, India
published: true
description: A facebook bot built using node js that diplays latest IT Job in Goa
tags: #showdev,#bot,#javascript,#beginners
---

## TL;DR
[View source code on github](https://github.com/ns23/goa-startup-jobs-bot)

This weekend as a side project I created a simple Facebook chatbot, that notifies latest jobs posted on [starupgoa.org](http://startupgoa.org/jobs/#.W4w1d3UzbMV)

Goa is a land of Sea, Sand and Startups and [starupgoa.org](http://startupgoa.org/jobs/#.W4w1d3UzbMV) is one place where most of the IT jobs are posted.

The jobs on [starupgoa.org](http://startupgoa.org/jobs/#.W4w1d3UzbMV) are displayed like below.

![startup go jobs](https://thepracticaldev.s3.amazonaws.com/i/vsu68lojda7stfkyw6ro.png)

 
After looking in the network tab in chrome, I found the Ajax call that fetches jobs.

![startup goa ajax](https://thepracticaldev.s3.amazonaws.com/i/65vw5qkmwtlinrsrmybw.png)

To get the experience in javascript,es6, and MongoDB, I chose to build this bot with Javascript.

I found this awesome article on [Hackernoon](https://hackernoon.com/) on
[How to Build a Facebook Bot App Using Node.js](https://hackernoon.com/how-to-build-a-facebook-bot-app-using-node-js-74629d4243ec)

> The post will be very big if I start to explain the code line by. So I will quickly tell how the bot works.

## How bot works in general

1. Initially, I have fetched the latest 100 jobs from the website and have stored it in the database [used mlab as database].
2. When a Facebook user clicks on Get Started button, Bot captures that user's id and store it in the database. It is used to send the push notification.
3. When user types `latest jobs` in chat, bot fetches the latest five jobs from the database and displays it to the user.
4. I Wrote a cron job using [node-schedule](https://www.npmjs.com/package/node-schedule) that runs every day at 1 AM and fetches the latest jobs from the website and stores it in the database.
5. If during cron job new jobs are fetched then bot send the push notification to the user with new Job.


## Technology Stack

* __Backend__  : Node JS
* __Database__ : MongoDB [mlab](https://mlab.com/)
* __Server__   : [Heroku](https://www.heroku.com/)

## Major Node Packages Used.

* [Bootbot](https://www.npmjs.com/package/bootbot) - JavaScript Framework to build Facebook Messenger's Chat bots.
* [cheerio](https://www.npmjs.com/package/cheerio) - Html Parser
* [winston](https://www.npmjs.com/package/winston) - Logger 
* [node-schedule](https://www.npmjs.com/package/node-schedule) - To run cron job
* [request](https://www.npmjs.com/package/request) - Make API call


## Demo
{% youtube G9y7hLZsh_E %}

> Currently the bot is in development mode and is not available for everyone.

## Suggestions are welcome
If you have suggestions to improve the bot please do comment.

## Need Help
I want to write unit tests for this bot, but I am not getting how to start with writing unit tests. If someone can help me with it,I will be really grateful.

## Conclusion

This is a simple bot and I hope It will be helpful to the IT job seekers in Goa.