{"id":13518238,"url":"https://github.com/wit-ai/node-wit","last_synced_at":"2025-05-14T05:10:49.627Z","repository":{"id":7059627,"uuid":"56077169","full_name":"wit-ai/node-wit","owner":"wit-ai","description":"Node.js SDK for Wit.ai","archived":false,"fork":false,"pushed_at":"2023-02-21T19:41:17.000Z","size":326,"stargazers_count":2060,"open_issues_count":38,"forks_count":483,"subscribers_count":105,"default_branch":"main","last_synced_at":"2025-04-11T00:45:34.918Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wit-ai.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-04-12T15:52:47.000Z","updated_at":"2025-04-10T03:49:29.000Z","dependencies_parsed_at":"2023-10-12T06:04:51.248Z","dependency_job_id":"13fb3e73-17cb-4173-aaa5-db4ce47d3648","html_url":"https://github.com/wit-ai/node-wit","commit_stats":{"total_commits":100,"total_committers":38,"mean_commits":"2.6315789473684212","dds":0.81,"last_synced_commit":"8a5cfcbf5baf4d27ffca7e7e4d67556af708ef6c"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wit-ai%2Fnode-wit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wit-ai%2Fnode-wit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wit-ai%2Fnode-wit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wit-ai%2Fnode-wit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wit-ai","download_url":"https://codeload.github.com/wit-ai/node-wit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254076850,"owners_count":22010611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T05:01:42.504Z","updated_at":"2025-05-14T05:10:49.556Z","avatar_url":"https://github.com/wit-ai.png","language":"JavaScript","readme":"# Wit Node.js SDK [![npm](https://img.shields.io/npm/v/node-wit.svg)](https://www.npmjs.com/package/node-wit)\n\n`node-wit` is the Node.js SDK for [Wit.ai](https://wit.ai).\n\n## Install\n\nIn your Node.js project, run:\n\n```bash\nnpm install --save node-wit\n```\n\n## Quickstart\n\nRun in your terminal:\n\n```bash\nnode examples/basic.js \u003cWIT_TOKEN\u003e\n```\n\nSee `examples` folder for more examples. Some examples have associated .zip files, do not forget to import those [when creating a new app](https://wit.ai/apps) and grab your access token from the Settings section.\n\n### Messenger integration example\n\nSee `examples/messenger.js` for a thoroughly documented tutorial.\n\n### Overview\n\nThe Wit module provides a Wit class with the following methods:\n\n- `runComposerAudio` - the [Composer](https://wit.ai/docs/recipes#composer) integration for voice;\n- `runComposer` - the [Composer](https://wit.ai/docs/recipes#composer) integration for other inputs;\n- `converse` - the Wit [converse](https://wit.ai/docs/http/#post__converse_link) API;\n- `event` - the Wit [event](https://wit.ai/docs/http#post__event_link) API;\n- `message` - the Wit [message](https://wit.ai/docs/http#get__message_link) API;\n- `speech` - the Wit [speech](https://wit.ai/docs/http#post__speech_link) API;\n- `dictation` - the Wit [dictation](https://wit.ai/docs/http#post__dictation_link) API;\n- `synthesize` - the Wit [synthesize](https://wit.ai/docs/http#post__synthesize_link) API.\n\nYou can also require a library function to test out your Wit app in the terminal. `require('node-wit').interactive`\n\n### Wit class\n\nThe Wit constructor takes the following parameters:\n\n- `accessToken` - the access token of your Wit instance;\n- `actions` - the object of [client action definitions for Composer](https://wit.ai/docs/recipes#run-custom-code);\n- `logger` - (optional) the object handling the logging;\n- `apiVersion` - (optional) the API version to use instead of the recommended one\n\nThe `logger` object should implement the methods `debug`, `info`, `warn` and `error`.\nThey can receive an arbitrary number of parameters to log.\nFor convenience, we provide a `Logger` class, taking a log level parameter\n\nExample:\n\n```js\nconst {Wit, log} = require('node-wit');\n\nconst actions = {\n  confirm_order(contextMap) {\n    return {context_map: {...contextMap, order_confirmation: 'PIZZA42'}};\n  },\n};\n\nconst client = new Wit({\n  accessToken: MY_TOKEN,\n  actions,\n  logger: new log.Logger(log.DEBUG), // optional\n});\n\nconsole.log(client.message('set an alarm tomorrow at 7am'));\n```\n\n## .runComposerAudio()\n\nThe [Composer](https://wit.ai/docs/recipes#composer) integration for voice.\n\nTakes the following parameters:\n\n- `sessionId` - a unique string identifying the user session\n- `contentType` - the Content-Type header\n- `body` - the audio `Readable` stream\n- `contextMap` - the [context map](https://wit.ai/docs/recipes#custom-context) object\n\nEmits `partialTranscription`, `response` and `fullTranscription` events.\nRun the provided `actions` as instructed by the API response, and calls back with the resulting updated context map (unless the action returns `stop: true`).\nThe Promise returns the final JSON payload of the last API call ([POST /converse](https://wit.ai/docs/http#post__converse_link) or [POST\n/event](https://wit.ai/docs/http#post__event_link)).\n\nSee `lib/interactive.js` for an example.\n\n## .runComposer()\n\nThe [Composer](https://wit.ai/docs/recipes#composer) integration for other\ninputs, including text.\n\nTakes the following parameters:\n\n- `sessionId` - a unique string identifying the user session\n- `contextMap` - the [context map](https://wit.ai/docs/recipes#custom-context) object\n- `message` - the optional user text query\n\nEmits `response` events.\nRun the provided `actions` as instructed by the API response, and calls back with the resulting updated context map (unless the action returns `stop: true`).\nThe Promise returns the final JSON payload of the last [POST /event](https://wit.ai/docs/http#post__event_link) API call.\n\nSee `lib/interactive.js` for an example.\n\n## .converse()\n\nThe Wit [converse](https://wit.ai/docs/http/#post__converse_link) API.\n\nTakes the following parameters:\n\n- `sessionId` - a unique string identifying the user session\n- `contentType` - the Content-Type header\n- `body` - the audio `Readable` stream\n- `contextMap` - the [context map](https://wit.ai/docs/recipes#custom-context) object\n\nEmits `partialTranscription`, `fullTranscription`, and `response` events. Runs\nintermediate `actions` as instructed by the API.\n\nWe recommend to use `.runComposerAudio()` instead of this raw API.\n\n## .event()\n\nThe Wit [event](https://wit.ai/docs/http#post__event_link) API.\n\nTakes the following parameters:\n\n- `sessionId` - a unique string identifying the user session\n- `contextMap` - the [context map](https://wit.ai/docs/recipes#custom-context) object\n- `message` - the optional user text query\n\nEmits `response` events, and run intermediate `actions` as instructed by the API.\n\nWe recommend to use `.runComposer()` instead of this raw API.\n\n### .message()\n\nThe Wit [message](https://wit.ai/docs/http/#get__message_link) API.\n\nTakes the following parameters:\n\n- `q` - the text input you want Wit.ai to extract the information from\n- `context` - (optional) the [Context](https://wit.ai/docs/http/#context_link) object\n- `n` - (optional) the max number of intents and traits to get back\n\nExample:\n\n```js\nconst client = new Wit({accessToken: 'MY_TOKEN'});\nclient\n  .message('what is the weather in London?', {})\n  .then(data =\u003e {\n    console.log('Yay, got Wit.ai response: ' + JSON.stringify(data));\n  })\n  .catch(console.error);\n```\n\nSee `lib/interactive.js` for another example integration.\n\n### .speech()\n\nThe Wit [speech](https://wit.ai/docs/http#post__speech_link) API.\n\nTakes the following paramters:\n\n- `contentType` - the Content-Type header\n- `body` - the audio `Readable` stream\n- `context` - (optional) the [Context](https://wit.ai/docs/http/#context_link) object\n- `n` - (optional) the max number of intents and traits to get back\n\nEmits `partialTranscription`, `partialUnderstanding` and `fullTranscription` events.\nThe Promise returns the final JSON payload.\n\nSee `lib/interactive.js` for an example.\n\n### .dictation()\n\nThe Wit [dictation](https://wit.ai/docs/http#post__dictation_link) API.\n\nTakes the following paramters:\n\n- `contentType` - the Content-Type header\n- `body` - the audio `Readable` stream\n\nEmits `partialTranscription`, and `fullTranscription` events.\nThe Promise returns the final JSON payload.\n\nSee `examples/synthesize-speech.js` for an example.\n\n### .synthesize()\n\nThe Wit [synthesize](https://wit.ai/docs/http#post__synthesize_link) API.\n\nTakes the following paramters (click on link above for more details):\n\n- `q` - The query containting text to synthesize\n- `voice` - The voice name. For voices and styles available, see GET [voices.](https://wit.ai/docs/http#get__voices_link)\n- `style` - (optional) The style to speak in\n- `speed` - (optional) the speed the text is spoken\n- `pitch` - (optional) the pitch of the audio\n- `gain` - (optional) the gain of the audio\n\nThe Promise returns the final response, with the body containing the audio stream of the synthesized text.\n\nSee `examples/synthesize-speech.js` for an example.\n\n### interactive\n\nStarts an interactive conversation with your Wit app.\n\nFull conversational interactions:\nUse `!converse` to send an audio request from the microphone using Composer.\nEnter any text input to send a text request using Composer.\n\nOne-off natural language requests:\nUse `!speech` to send an audio request from the microphone.\nUse `!message \u003cyour message\u003e` to send a text request.\n\nExample:\n\n```js\nconst {interactive} = require('node-wit');\ninteractive(client);\n```\n\nSee the [docs](https://wit.ai/docs) for more information.\n\n## Changing the API version\n\nThe default (recommended, latest) API version is set in `config.js`.\n\nOn May 13th, 2020, the `GET /message` API was updated to reflect the new data model: intents, traits and entities are now distinct.\nYou can target a specific version by passing the `apiVersion` parameter when creating the `Wit` object.\n\n```json\n{\n  \"text\": \"hello\",\n  \"intents\": [\n    {\n      \"id\": \"1353535345345\",\n      \"name\": \"greet\",\n      \"confidence\": 0.9753\n    }\n  ],\n  \"entities\": [],\n  \"traits\": []\n}\n```\n\n## Running tests\n\n1. Create a new app in wit.ai web console using tests/wit-ai-basic-app-for-tests.zip\n2. Copy the Server Access Token from app settings\n3. Run `WIT_TOKEN=XXX npm test`, where XXX is the Server Access Token\n\n## License\n\nThe license for node-wit can be found in LICENSE file in the root directory of\nthis source tree.\n\n## Terms of Use\nOur terms of use can be found at https://opensource.facebook.com/legal/terms.\n\nUse of Wit.ai services fall under the terms of use found here: https://wit.ai/terms.\n\n## Privacy Policy\nOur privacy policy can be found at https://opensource.facebook.com/legal/privacy.\n\nThe privacy policy for the Wit.ai service can be found at https://wit.ai/privacy.\n","funding_links":[],"categories":["JavaScript","\u003ca name=\"JavaScript\"\u003e\u003c/a\u003eJavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwit-ai%2Fnode-wit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwit-ai%2Fnode-wit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwit-ai%2Fnode-wit/lists"}