Coder Social home page Coder Social logo

chat-app's Introduction

Welcome To Nai Hack 2022

In here is a sample application containing boiler place that you will use to buld your whatsapp chat bot.

Below are the environmental variables you need to configure.

Env Variables

MONGO_DB_URL

  • Group One mongodb+srv://makinika:[email protected]/naihack-one?retryWrites=true&w=majority

  • Group Two mongodb+srv://makinika:[email protected]/naihack-two?retryWrites=true&w=majority

  • Group Three mongodb+srv://makinika:[email protected]/naihack-three?retryWrites=true&w=majority

  • Group Four mongodb+srv://makinika:[email protected]/naihack-four?retryWrites=true&w=majority

  • Group Five mongodb+srv://makinika:[email protected]/naihack-five?retryWrites=true&w=majority

Set Up Testing Phone and CallBack Url

Below are the data objects for each group they are explained in detail below.

{
    "_id": "62c55381a0994cc353004d3a",
    "name": "Group 1",
    "link": "https://9e50-197-232-74-189.ngrok.io/callback",
    "phone": "254XXXXXXXXX",
    "__v": 0
}

{
    "_id": "62c57f9480da8d9593bb49e4",
    "name": "Group 2",
    "link": "https://fce5-197-232-74-189.ngrok.io",
    "phone": "254XXXXXXXXX",
    "__v": 0
}

{
    "_id": "62c57f9c80da8d9593bb49e6",
    "name": "Group 3",
    "link": "https://fce5-197-232-74-189.ngrok.io",
    "phone": "254XXXXXXXXX",
    "__v": 0
}

{
    "_id": "62c57fa280da8d9593bb49e8",
    "name": "Group 4",
    "link": "https://fce5-197-232-74-189.ngrok.io",
    "phone": "254XXXXXXXXX",
    "__v": 0
}

{
    "_id": "62c57fa780da8d9593bb49ea",
    "name": "Group 5",
    "link": "https://fce5-197-232-74-189.ngrok.io",
    "phone": "254XXXXXXXXX",
    "__v": 0
}

Field Explanation

  • _id - The unique identifiere of a group which will be used to update the groups testing phone number and whatsapp callback url if need be

  • name - The name of the group.

  • link - The callback url where WhatsApp will send the message that has been sent by your user..

  • phone - phone number that is being used for testing purposes.

Update Group Request

If you may want to update your group's callback url or testing phone number, below is a sample curl request.

curl --location --request PUT 'https://hackathon-4-proxy.onrender.com/api/v1/groups/62c55381a0994cc353004d3a' \
--header 'Content-Type: application/json' \
--data-raw '{
    "link":"https://9e50-197-232-74-189.ngrok.io/callback",
    "phone":"254797792447"
}'

Expected User Journey

  • User starts chat with the Chatbot
  • Chatbot asks for their Number plate if there are none in the, and user provides(if they have used the chatbot before, it should provide previously used number plates)
  • Chatbot sends the number plate to the parking api, and parking api returns to the chatbot if it exists or not. If it exists, returns with amount due, and duration of stay, and a cta to pay. If not, user is asked to input valid number plate.
  • Once user clicks Pay, the chatbot asks them to confirm the number they are paying with(if they have used the chatbot before, it should show previously used numbers)
  • Once user selects or inputs the number, the chatbot lets them know to check their phone for an mpesa prompt
  • If user pays Successfully; the Chatbot should message the user, letting them know that they have paid successfully, for Number plate x - duration of stay.
  • The chatbot should also send a positive trigger to the Parking api, letting it know that number plate x has been paid, and hence approved to be opened.
  • If user's payment fails, the chatbot should let the user know that payment has failed, and should also send a negative trigger to the parking api, letting it know number plate x payment failed, hence state to stay unpaid and closed.

WhatsApp Send Messages Documentation

WhatsApp Send Messages Documentation

Staging Links

  • Group One https://hackathon-4-team-one.onrender.com

  • Group Two https://hackathon-4-team-two.onrender.com

  • Group Three https://hackathon-4-team-three.onrender.com

  • Group Four https://hackathon-4-team-four.onrender.com

  • Group Five https://hackathon-4-team-five.onrender.com

MPESA GATEWAY

  • MPESA ENDPOINT https://es9b8fu024.execute-api.eu-west-1.amazonaws.com/naihack/pay

-The above endpoint accepts only post requests -For authorization purposes, include the below header in your request

AuthorizationToken dessd1S4Ssd3r3rkd2fHdysbd09sddGKtwDBPJ

-Supply the following to initiate a payment. Ideally, account reference will be your vehicle number

int Amount

string PhoneNumber

string NotificationCallBackUrl (An endpoint that I can push the mpesa payment notification once user has completed the payment process)

string AccountReference

-See below

let config = {
  headers: {
    AuthorizationToken: "dessd1S4Ssd3r3rkd2fHdysbd09sddGKtwDBPJ",
  }
}

axios.post(' https://es9b8fu024.execute-api.eu-west-1.amazonaws.com/naihack/pay', {
	phoneNumber: "+2547XXXXXXXX",
    amount: 10,
    accountReference: "KDA377X",
    NotificationCallBackUrl: "https://{your handler url}"
}, config)
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
const axios = require('axios');

const sendMessage = (body) => {
    const url = `https://waba.360dialog.io/v1/messages`
    const headers = {
        'Content-Type': 'application/json',
        'D360-API-KEY': 'FSHBI59lo6uLQBarrtWxAO1mAK'
    }
    axios.post(
        url,
        body,
        {
            headers:headers
        }
    ).catch(
        (e) => {
            console.log(e)
        }
    )
}
module.exports = {
    sendMessage 
}
 https://31bb-41-139-133-17.ngrok.io

chat-app's People

Contributors

hackathongranularit avatar daniel-waruo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.