Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Facebook information
APP_SECRET=
VERIFY_TOKEN=
ACCESS_TOKEN=

# Database and server setup
MONGODB_URI=
BOT_PORT=1337
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"extends": "eslint:recommended",
"globals": {
"process": true,
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
Expand All @@ -14,4 +15,4 @@
},
"rules": {
}
}
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
node_modules
**/.env

# OSX
**/.DS_Store

# Editors
.idea
.vscode/

# Assets
generated/*.png
1 change: 1 addition & 0 deletions PRIVACY_POLICY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<h2>Privacy Policy</h2>

<p>Your privacy is important to us. It is CodeCanary's policy to respect your privacy regarding any information we may collect from you across our website, <a href="https://codecanary.now.sh">https://codecanary.now.sh</a>, and other sites we own and operate.</p>
<p>We only ask for personal information when we truly need it to provide a service to you. We collect it by fair and lawful means, with your knowledge and consent. We also let you know why we’re collecting it and how it will be used.</p>
<p>We only retain collected information for as long as necessary to provide you with your requested service. What data we store, we’ll protect within commercially acceptable means to prevent loss and theft, as well as unauthorised access, disclosure, copying, use or modification.</p>
Expand Down
28 changes: 23 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Code Canary

<p align="center">
<img src="https://i.imgur.com/L8gxQk0.png" alt="logo" height=200/>
<img src="https://i.imgur.com/L8gxQk0.png" alt="logo" height=200/>
</p>


Expand All @@ -22,6 +22,22 @@ Interactive learning 👩🏼‍🎓 for youths and children 🧒🏽🧒🏽 wh
npm start
```

1. Create an `.env` file and fill in the values.

- Run `cp .env.example .env` to create a `.env` file.
- Go to [https://developers.facebook.com/](), login and copy the messenger credentials.
- Take `mongodb://localhost:27017/codeCanary` as the default value for `MONGODB_URI`.

2. Start the development server - this will start a mongodb server

```bash
yarn start
```

## Code

`DAO`: `Data Access Object`

## Inspiration
Code Canary provides early access to technological empowerment for youths who do not have access to formal training, computers and internet.

Expand All @@ -41,7 +57,7 @@ Moreover, mobile service providers in Africa offer cheap bundles to support acce

The bot was divided into services such as the database, assignment service, messaging services, NLP which were assigned to different team members to develop and bring together. A demo version/prototype was hosted for review and redesigned before publishing the final version.

## Challenges we ran into
### Challenges we ran into
Learning how to use the messenger bot was a challenge as none of the team members was conversant with it.
Given the contextual variations, adapting the NLP to user responses was a challenge
Designing the interactive flow for meaningful user experience was a challenge
Expand All @@ -55,12 +71,13 @@ Building a messenger bot
* Insight into the 4 SDGs and the implications for tech solutions
* Insight into content development for coding instruction

## What's next for Code Canary
### What's next for Code Canary
- Make the bot more engaging and interactive
- Advancing the content level from basic programming
- Enabling the learners to publish the homepage they develop so as to market themselves

## Built With
### Built With

- Node.js
- JavaScript
- Facebook Messenger API
Expand All @@ -69,5 +86,6 @@ Building a messenger bot
- Facebook Graph API

## Try it out

- [Website](https://codecanary.now.sh/)
- [F8 Hackathon submission page](https://devpost.com/software/icode)
- [F8 Hackathon submission page](https://devpost.com/software/icode)
34 changes: 25 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
'use strict';

require('dotenv').config();
const BootBot = require('bootbot');

const APP_SECRET = process.env.APP_SECRET;
const VERIFY_TOKEN = process.env.VERIFY_TOKEN;
const ACCESS_TOKEN = process.env.ACCESS_TOKEN;

/**
* DAO Section
*
* Initialize DB connection
* Initialize models
*/
Expand All @@ -17,7 +23,7 @@ const User = require('./dao/models/user');
const Question = require('./dao/models/question').Question;
const APIController = require('./controllers/APIController');
const constructTemplateResponse = require('./service/messengerService').constructTemplateResponse;
const seachMatchingPicture = require('./service/messengerService').seachMatchingPicture;
const searchMatchingPicture = require('./service/messengerService').searchMatchingPicture;

// Call seeder for sample lessons.
require('./dao/seeder/lessonSeeder');
Expand All @@ -31,14 +37,24 @@ const
body_parser = require('body-parser'),
app = express().use(body_parser.json()); // creates express http server

const bot = new BootBot({
accessToken: ACCESS_TOKEN,
verifyToken: VERIFY_TOKEN,
appSecret: APP_SECRET
});

APIController.setupUserConversation(bot);

bot.start(1337);

// Webhook BOT routes
app.get('/webhook', APIController.verifyServer);
app.post('/webhook', APIController.handleWebhookEvent);
// app.get('/webhook', APIController.verifyServer);
// app.post('/webhook', APIController.handleWebhookEvent);

// Handles rendering of the user homepage
app.get('/render', function (req, res) {
APIController.renderHtml(req, res, User);
});
// // Handles rendering of the user homepage
// app.get('/render', function (req, res) {
// APIController.renderHtml(req, res, User);
// });

// Sets server port and logs message on success
app.listen(process.env.PORT || 1337, () => console.log('webhook is listening'));
// // Sets server port and logs message on success
// app.listen(process.env.PORT || 1337, () => console.log('webhook is listening'));
53 changes: 0 additions & 53 deletions chatbot_bl/l/intents.js

This file was deleted.

35 changes: 34 additions & 1 deletion controllers/APIController.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,38 @@ function verifyServer(req, res) {
}
}

function setupUserConversation(bot) {
bot.hear('ask me something', (payload, chat) => {

const askName = (convo) => {
convo.ask(`What's your name?`, (payload, convo) => {
const text = payload.message.text;
convo.set('name', text);
convo.say(`Oh, your name is ${text}`).then(() => askFavoriteFood(convo));
});
};

const askFavoriteFood = (convo) => {
convo.ask(`What's your favorite food?`, (payload, convo) => {
const text = payload.message.text;
convo.set('food', text);
convo.say(`Got it, your favorite food is ${text}`).then(() => sendSummary(convo));
});
};

const sendSummary = (convo) => {
convo.say(`Ok, here's what you told me about you:
- Name: ${convo.get('name')}
- Favorite Food: ${convo.get('food')}`);
convo.end();
};

chat.conversation((convo) => {
askName(convo);
});
});
}

function handleWebhookEvent(req, res) {

// Parse the request body from the POST
Expand Down Expand Up @@ -93,6 +125,7 @@ function handleWebhookEvent(req, res) {

module.exports = {
verifyServer: verifyServer,
handleWebhookEvent: handleWebhookEvent,
handleWebhookEvent,
setupUserConversation,
renderHtml
}
3 changes: 2 additions & 1 deletion dao/connector.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
let mongoose = require('mongoose');

const url = process.env.MONGODB_URI;

function connect() {
mongoose.connect(url, { useNewUrlParser: true });
}

module.exports = connect;
module.exports = connect;
Loading