Search code examples
javascriptpythonagentdialogflow-es-fulfillment

How to write fulfillment code from an IDE instead of the inline editor?


I was wondering if it is possible to use a preferred IDE rather than code your fulfillment functions in the provided in-line editor? If so, can anyone provide steps/links to set up the communication between an IDE and the designated Agent?

P.S. I've already tried using the Dialogflow API, and being that I don't want to implement my agent into a website, it was no use.


Solution

  • Here you go, you can use the below step to connect your server for Dialogflow fulfillment.

    1. Create your server in preferred language (I have used NodeJS/Express)
    2. when you get this running on localhost, expose it so that dialogflow can connect to your server.
    3. Use ngrok for proxy expose.
    4. Add fulfillment details in Dialogflow.
    5. Write your code locally.

    app.js

    const app = express();
    app.use('/assets', express.static(path.join(__dirname, 'assets')))
    app.get("/", (req, res) => res.send("online"));
    app.post("/dialogflow", express.json(), (req, res) => {
        const agent = new WebhookClient({ request: req, response: res });
    
        let intentMap = new Map();
        intentMap.set("Default Welcome Intent", welcome);
        intentMap.set("Exit Intent", exit);
    });
    function exit(agent){}
    function welcome(agent){}
    

    Run Ngrok and get the public link run ngrok get the public link

    Add these server details in Dialogflow fulfillment enter image description here

    Note: This is only for local development later you can add a real production server url where your fulfillment will be running.