Search code examples
typescriptdialogflow-es

How to use 'dialogflow' client library with Typescript?


I have a working Typescript codebase, running server-side in NodeJS v10.18.0 and I am trying to integrate the 'dialogflow' client library into it.

Note that this is NOT the dialogflow webhook/fulfilment API. It's the client API.

But I can't get 'dialogflow' to 'import' with Typescript, any which way, even though @types/dialogflow claims that the package is properly typed already.

Basic test case:

Start in an empty folder somewhere, then:

$ npm init     # Accept all defaults
$ tsc --init
$ npm install --save dialogflow @types/node

Now create index.ts containing:

import * as df from 'dialogflow'

You can try other import styles. They all hit the same problem.

Then try:

$ tsc

It complains with:

index.ts:1:29 - error TS7016: Could not find a declaration file for module 'dialogflow'.

What gives? What am I doing wrong?

(I am not an expert on module typing with Typescript)

Is dialogflow typed for Typescript or not?


Solution

  • Currently only option is to use deprecated version.

    Install

    npm i -D @types/dialogflow@0.11.0
    

    Code

    import * as df from 'dialogflow';
    const config = { ... };
    const sessionClient = new df.SessionsClient(config);
    

    Refer this comment. Hope the official library will be fixed soon.

    Note following option does not work, as it don't have correct type definitions.

    import * as dialogflow from 'dialogflow/protos/protos'