Catalog npm
Back to packageRELEASE DETAILS

2.1.1

npm

@0xc/dialogflow-as-code

![npm (scoped)](https://img.shields.io/npm/v/@0xc/dialogflow-as-code) [![builds.sr.ht status](https://builds.sr.ht/~tcarrio/dialogflow-as-code/.build.yml.svg)](https://builds.sr.ht/~tcarrio/dialogflow-as-code/.build.yml?) [![License](https://img.shields.i

Published23 Jun 2020
Direct dependencies32
Transitive dependenciesNot calculated

README

Current package documentation

npm (scoped) builds.sr.ht status License

dialogflow-as-code

This package allows the creation of Dialogflow resources by using the nodejs-dialogflow project along with the types we have helped define in @types/dialogflow. It was developed using Node.js and TypeScript.

The builder helpers can be used for generating resources, however the module also allows for objects to be directly passed to the builder. The builders eventually generate the same types expected by the nodejs-dialogflow API, so whichever you find easier will work fine. For some of the more advanced types, it can be much easier to work with the builders. The following provides several examples of defining Dialogflow resources and how they eventually tie together to be created and synced to a Dialogflow agent:

// Sample Entity Type Builder
export const etFruit = entityType()
  .d("fruit")
  .e([syn("apple"), syn("strawberry")])
  .k(ek.list)
  .build();
// Sample Entity Type
export const etSample: EntityType = {
  displayName: "sample",
  entities: [{ value: "sample", synonyms: ["piece", "swab", "choice"] }],
  kind: "KIND_MAP",
  autoExpansionMode: "AUTO_EXPANSION_MODE_DEFAULT",
};
// Sample Context Builder
export const cxFruit = cx()
  .n("fruit-context")
  .lc(5)
  .p("date-time-original", "string_value")
  .build();
// Sample Events
export enum Event {
  FEEDBACK = "FEEDBACK",
  YES = "YES",
  NO = "NO",
}
// Sample Intent
// prettier-ignore
export const ntFruitInfo = intent("fruitInfo")
  .priority(Priority.LOW)
  .webhook(true)
  .trainingPhrases([
    tp(["describe the ", pb("sample"), " of ", etFruit, " over ", det("date-time")]),
    tp(["how was the ", pb("sample"), " of ", etFruit]),
    tp([pb("sample"), " of ", etFruit, " ", det("date-time")]),
    tp([pb("sample"), " of ", etFruit]),
    tp(["what was the ", pb("sample"), "inputContextsf ", etFruit, " ", det("date-time"), "?"]),
    tp(["what was the ", pb("sample"), " of ", etFruit]),
  ])
  .messages([
    msg("text").set(["I'm sorry Dave, I can't do that"]).build(),
    msg("text").set(["Second response"]).build(),
  ])
  .events([Event.FEEDBACK])
  .outputContexts([cxFruit])
  .followUpOf(ntFruitReminder);
// Sample Resource Build and Sync Script
const svcAcctKeyJson: string = "./service-account-key.json";
const svcAcctConfig: DialogflowServiceAccount = require(`.${svcAcctKeyJson}`);
Container.set(KEY_FILENAME, svcAcctKeyJson);
Container.set(DIALOGFLOW_CONFIG, svcAcctConfig);

const resources = Container.get(DialogflowBuilder)
  .entityTypes([etSample, etFruit])
  .intents([ntFruitInfo, ntFruitReminder])
  .build();

Container.get(DialogflowCreator).sync(resources);

Note: You will need to create a service account on the Dialogflow website and provide it at the project level as service-account-key.json. The file path and config object are passed to the DialogflowBuilder. The path can be changed, this is just the sample and converted project expectations.

If you would like to to take it for a spin, you can run the provided project sample:

git clone https://git.sr.ht/~tcarrio/dialogflow-as-code
pushd dialogflow-as-code
npm i
npm run sample

dialogflow-converter

This project contains a module for converting resources exported from Dialogflow into resources for use by dialogflow-as-code. These are rudimentary at the moment, with future improvements planned for the templating structure and full feature-set of dialogflow-as-code.

Run the conversion by calling npm start -- -i $input_path -o $output_path. It can also be directly invoked with node, by calling node lib/converter/dialogflow-converter.js.

If this package was installed, it is available at the bin directory of the installation scope (locally at node_modules/.bin/dialogflow-as-code or globally at $NODE_HOME/bin/dialogflow-as-code).

The easiest way to get started with building out a dialogflow-as-code project is to npm i -g dialogflow-as-code. With this available you can use its CLI to specify input and output directories for generating the code from an extracted Dialogflow export.

Usage: dialogflow-as-code [options]

Generate a Dialogflow-as-Code project from a Dialogflow export

Options:
  -V, --version       output the version number
  -o, --output <dir>  Output directory (default: ./output)
  -i, --input <dir>   Input directory (default: ./input)
  -h, --help          output usage information

The converter also makes use of prettier to format the project after its creation.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 32

Native requirements
32 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
commander
Environment
{
  "local_name": "commander",
  "alias": false,
  "peer_metadata": null
}
^2.20.0runtime
dialogflow
Environment
{
  "local_name": "dialogflow",
  "alias": false,
  "peer_metadata": null
}
^1.2.0runtime
figlet
Environment
{
  "local_name": "figlet",
  "alias": false,
  "peer_metadata": null
}
^1.2.3runtime
glob
Environment
{
  "local_name": "glob",
  "alias": false,
  "peer_metadata": null
}
^7.1.4runtime
googleapis
Environment
{
  "local_name": "googleapis",
  "alias": false,
  "peer_metadata": null
}
^39.2.0runtime
joi
Environment
{
  "local_name": "joi",
  "alias": false,
  "peer_metadata": null
}
^14.3.1runtime
lodash
Environment
{
  "local_name": "lodash",
  "alias": false,
  "peer_metadata": null
}
^4.17.11runtime
prettier
Environment
{
  "local_name": "prettier",
  "alias": false,
  "peer_metadata": null
}
^1.16.4runtime
reflect-metadata
Environment
{
  "local_name": "reflect-metadata",
  "alias": false,
  "peer_metadata": null
}
^0.1.13runtime
typedi
Environment
{
  "local_name": "typedi",
  "alias": false,
  "peer_metadata": null
}
^0.8.0runtime
uuid
Environment
{
  "local_name": "uuid",
  "alias": false,
  "peer_metadata": null
}
^3.3.2runtime
@types/debug
Environment
{
  "local_name": "@types/debug",
  "alias": false,
  "peer_metadata": null
}
^4.1.4development
@types/dialogflow
Environment
{
  "local_name": "@types/dialogflow",
  "alias": false,
  "peer_metadata": null
}
^0.9.4development
@types/glob
Environment
{
  "local_name": "@types/glob",
  "alias": false,
  "peer_metadata": null
}
^7.1.1development
@types/jest
Environment
{
  "local_name": "@types/jest",
  "alias": false,
  "peer_metadata": null
}
^24.0.13development
@types/lodash
Environment
{
  "local_name": "@types/lodash",
  "alias": false,
  "peer_metadata": null
}
^4.14.129development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^12.12.0development
@types/prettier
Environment
{
  "local_name": "@types/prettier",
  "alias": false,
  "peer_metadata": null
}
^1.16.4development
@types/uuid
Environment
{
  "local_name": "@types/uuid",
  "alias": false,
  "peer_metadata": null
}
^3.4.5development
@types/figlet
Environment
{
  "local_name": "@types/figlet",
  "alias": false,
  "peer_metadata": null
}
^1.2.0development
@types/joi
Environment
{
  "local_name": "@types/joi",
  "alias": false,
  "peer_metadata": null
}
^14.3.3development
@typescript-eslint/eslint-plugin
Environment
{
  "local_name": "@typescript-eslint/eslint-plugin",
  "alias": false,
  "peer_metadata": null
}
^1.7.0development
@typescript-eslint/parser
Environment
{
  "local_name": "@typescript-eslint/parser",
  "alias": false,
  "peer_metadata": null
}
^1.7.0development
eslint
Environment
{
  "local_name": "eslint",
  "alias": false,
  "peer_metadata": null
}
^5.16.0development
eslint-config-prettier
Environment
{
  "local_name": "eslint-config-prettier",
  "alias": false,
  "peer_metadata": null
}
^4.2.0development
eslint-plugin-prettier
Environment
{
  "local_name": "eslint-plugin-prettier",
  "alias": false,
  "peer_metadata": null
}
^3.0.1development
jest
Environment
{
  "local_name": "jest",
  "alias": false,
  "peer_metadata": null
}
^24.9.0development
jest-junit
Environment
{
  "local_name": "jest-junit",
  "alias": false,
  "peer_metadata": null
}
^6.4.0development
nodemon
Environment
{
  "local_name": "nodemon",
  "alias": false,
  "peer_metadata": null
}
^1.19.0development
ts-jest
Environment
{
  "local_name": "ts-jest",
  "alias": false,
  "peer_metadata": null
}
^24.0.2development
ts-node
Environment
{
  "local_name": "ts-node",
  "alias": false,
  "peer_metadata": null
}
^8.0.3development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
3.4.5development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-HV5ueiBxca7+ZHOhK6UYwDs7NpZNc7MQOXvF5rAb+pjEpu0qSTi0Al1W18cvG9a6kXlu6QF/3ZKBrANigrA2nw==",
  "shasum": "060bd16395e4e30a8bd228aca05336c70a13a035",
  "tarball": "https://registry.npmjs.org/@0xc/dialogflow-as-code/-/dialogflow-as-code-2.1.1.tgz",
  "fileCount": 4,
  "unpackedSize": 19978,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJe8l+HCRA9TVsSAnZWagAAp9IQAIhtEntdtOPBl1etY/ib\nh1Z57homlQnsaQN+XJzqm+AP5tkxXlNH+OYzZhil2/5PFs68d76dTqlbEoLi\nRKvLiIF2r0oSvhdbNimsfzhFc11A1XiMPhd2t5pZJDI94djz/UziZcEf19n6\n9YNJe1B1JfNVYkAHrS7m5FqIobE2ZvBxWAdmM40FnEG4QalOIRyVSAS0BEl4\nohob1hG/2eEPqd4DwnLj+mMd1RhgqHlWPXSM1uVVA4QymCsr2nL22Te/hwaI\nz1RSLF/mvUd/fh6iN4NV2SjxBdwf0NUTYBy6wZznCobElE3z7ztu1RgHbTcR\nLlwg/R/S0nw0J8fDlBwb+HvwxVx5EZGm/1g6xfCDdxBlN04n83EI/IM+cmT3\naPFfxX8nX8o8UohQlr0I6NhF57anYzvGVuu+5nqAFI5VKk059iUxFUdVb1Al\nToOQZstn4wlkpCaqz67+adXT6XeJH3KWp/C2Yquv31PjxXKO7txgYBxEeB7P\nr1ylHyjnA/DN6NBL9mZ3lw5JquIxjks01pbFIyD6yMtvvml/ea4ihmi9woW7\nYlrOOjehJ1RvQf1AVHYCdAyHVGp7JUETU7u7hTk9pVoOlJQqysmgOiZUsOF6\n5s75sZynYBAf24wewZ0oL7RNVHq5N3yYCEivwqo3ev9O0ewwd4cuLnwkct3w\nlnZC\r\n=5OHV\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEYCIQCj4ODUnDmB0TF67KPrwgsSlyvavApWJudAd7Ri9X1G7wIhAIFQEQ2LrPsCnpq7cmHDz91tdbW7ayRp0FP33CzEZtb9"
    }
  ]
}

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:44 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:e66aae869a38b74eb6307265cf55fc8f27cdd1edaaed049022d3a1081e7aa56f

Other collected versions

3.0.0-beta318 Oct3.0.0-beta217 Oct3.0.0-beta117 Oct2.1.0-beta.012 Jun2.0.012 JunView all collected versions →