async function is only available in ES8 dialogflow

3,569 views
Skip to first unread message

Ayham Darwish

unread,
Sep 24, 2020, 11:30:53 AM9/24/20
to Dialogflow Essentials Edition users
Hey
i am trying to use async in dailogflow to call an google translate API but i got this error that async function is only available in ES8 and i checked if there is solution in internet but i did not find. 
this is the code i wrote: 
async function detectLanguage(agent , text , target) {
  const translate = new Translate();
  let [translations] = await translate.translate(text, target);
  //translations = Array.isArray(translations) ? translations : [translations];
  agent.add('Translations:');
  translations.forEach((translation, i) => {
    agent.add(`${text[i]} => (${target}) ${translation}`);
  });
}
 and :
function test(agent) {
  const text = 'hej';
  const target = 'en';
    return detectLanguage(agent, text, target).then(result => {
    agent.add('${result}');
    });
  }
please anyone can help me 

Ted Liu

unread,
Sep 24, 2020, 9:35:15 PM9/24/20
to Dialogflow Essentials Edition users
If you're using the inline editor, you cannot use async, you will have to use the Promise.

But there's another way to use async, which is to develop locally, so you can use  ES8, you will have to use the ngrok and turn on the webhook for the intents.

Could check out the link as follows and do it step by step, it's pretty easy.

Sahil Manekia

unread,
Apr 4, 2021, 11:38:34 AM4/4/21
to Dialogflow Essentials Edition users
Assuming you found a solution, but I inserted this piece of code in the inline editor which allows async functions to run

// for Dialogflow fulfillment library docs, samples, and to report issues

'use strict';

// try without jshint and with
/* jshint esversion: 8 */ 

Reply all
Reply to author
Forward
0 new messages