3

I want to connect my dialogflow chatbot to this API. so that, whenever I write "Where does Quran talk about Allah", it goes to this api and make HTTP get request to https://islam360api.herokuapp.com/Allah and returns the response.

I have turned on the "Webhook" in the intent and added the api link in as dialogflow fulfilment url. But how to teach dialogflow to concatenate the word "Allah" after or anything else user might say with each api call to https://islam360api.herokuapp.com and make HTTP get request and returns the response? Do I need to use action? What for? or Do I need to use inline editor, instead of "Webhook" under fulfillment?

EDIT

app.js

const sqlite3 = require('sqlite3').verbose();

const express = require("express");

// Notice that the execution mode is set to verbose to produce long stack traces.

var app = express();

var ayats=[];


app.get("/:find",function(request, response)

{

    let db = new sqlite3.Database("./file.db",(err) => {

        if (err){

        console.log("Not connected to sqlite")

        }

        else{

            console.log("Connected to sqlite")

        }

    });

    // The sqlite3.Database() returns a Database object and opens the database connection automatically.

    

    let sql = `SELECT SuratNameEng, AyatNo, English FROM surah`;

 

db.all(sql, [], (err, rows) => {

  if (err) {

    throw err;

  }

  rows.forEach((row) => {

    ayats.push(JSON.stringify({Translation: row.English,SuratName: row.SuratNameEng,AyatNo: row.AyatNo}));

  });

  console.log(ayats);

  ayats.forEach(function(element) {

    if (element.toLowerCase().includes(request.params.find.toLowerCase())===true)

    {

      element=JSON.parse(element)

      response.write(JSON.stringify({speech: "In"+ element.SuratName+", Ayat Number: "+element.AyatNo+", Quran says: "+ element.Translation, displayText: "In"+ element.SuratName+", Ayat Number: "+element.AyatNo+", Quran says: "+ element.Translation}))

    }

  });

  response.send();

});



empty();

function empty() {

    ayats.length = 0;

}


db.close((err) => {

    if (err) {

      return console.error(err.message);

    }

    console.log('Close the database connection.');

  });

    

})

 

// It is a good practice to close a database connection when you are done with it. 

var port = process.env.PORT || 3000;

app.listen(port,()=>console.log("Active"));

Github repository: https://github.com/ukashasohail/i360-api

Muhammad Naufil
  • 2,420
  • 2
  • 17
  • 48

1 Answers1

2

Actually you need to write your own server and give the link to in dialogflow fulfillment, I recommend you to use firebase functions as your server since it is easy to understand.

You also need to use sys.any entity since your user might say anything, such as user might also say, "where does Quran talk about {sys.any}" Any means any text string, I would recommend you to make this training phases of intent in template mode instead of example mode. (https://dialogflow.com/docs/intents/training-phrases)

https://youtu.be/XfTQ3Z_-6Sk

https://youtu.be/QqMdzrvfNBo

https://youtu.be/eLocziyi-Qw

As a reference Watch these videos, I am teaching how to use firebase functions as fulfilment webhook and how to use database to store your customers hotel booking, instead of using database you need to make an https request (ideally using npm request module https://www.npmjs.com/package/request)

Note: the given videos link is on dialogflow v1 which is outdated, but it still convey the basic idea so it is still helpful Note: firebase functions doesn't allow you to make http request in free mode, inline editor is also firebase functions, other options are express server with combination of heroku Note: these videos are using json request response to dialogflow, Ultimately i would recommend you to use dialogflow fulfilment library for this purpose (https://github.com/dialogflow/dialogflow-fulfillment-nodejs)

Muhammad Naufil
  • 2,420
  • 2
  • 17
  • 48
Inzamam Malik
  • 3,238
  • 3
  • 29
  • 61