-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: as title, see `CHANGES.md` + prettier Reviewed By: jayyteee Differential Revision: D38368445 fbshipit-source-id: 251701fc147e98019bb50bcb7e06517089c06f39
- Loading branch information
1 parent
8237f61
commit d18b975
Showing
6 changed files
with
440 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
let Wit = null; | ||
let interactive = null; | ||
try { | ||
// if running from repo | ||
Wit = require('../').Wit; | ||
interactive = require('../').interactive; | ||
} catch (e) { | ||
Wit = require('node-wit').Wit; | ||
interactive = require('node-wit').interactive; | ||
} | ||
|
||
const accessToken = (() => { | ||
if (process.argv.length !== 3) { | ||
console.log('usage: node examples/pizza.js <wit-access-token>'); | ||
process.exit(1); | ||
} | ||
return process.argv[2]; | ||
})(); | ||
|
||
const actions = { | ||
process_order(contextMap) { | ||
const {order} = contextMap; | ||
if (typeof order !== 'object') { | ||
console.log('could not find order'); | ||
return {context_map: contextMap}; | ||
} | ||
|
||
const pizze = Array.from(order.pizze || []); | ||
const pizze_number = pizze.length; | ||
if (pizze_number < 1) { | ||
console.log('could not find any pizze in the order'); | ||
return {context_map: contextMap}; | ||
} | ||
|
||
const processed = pizze.length; | ||
const order_number = pizze[0].type.substring(0, 3).toUpperCase() + '-42X6'; | ||
|
||
return {context_map: {...contextMap, pizze_number, order_number}}; | ||
}, | ||
make_summary(contextMap) { | ||
const {order} = contextMap; | ||
if (typeof order !== 'object') { | ||
console.log('could not find order'); | ||
return {context_map: contextMap}; | ||
} | ||
|
||
const pizze = Array.from(order.pizze || []); | ||
if (pizze.length < 1) { | ||
console.log('could not find any pizze in the order'); | ||
return {context_map: contextMap}; | ||
} | ||
|
||
const order_summary = pizze | ||
.map(({size, type}) => 'a ' + size + ' ' + type) | ||
.join(', '); | ||
|
||
return {context_map: {...contextMap, order_summary}, stop: true}; | ||
}, | ||
}; | ||
|
||
const client = new Wit({accessToken, actions}); | ||
interactive(client); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.