{"_id":"@bottender/proposal-conversation","_rev":"4-f79323e2cf8c434a745f05980c8713cb","name":"@bottender/proposal-conversation","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@bottender/proposal-conversation","version":"0.1.0","description":"A candidate of the Bottender conversation module","main":"index.js","scripts":{"lint":"eslint *.js examples","lint:fix":"yarn lint:fix:md && yarn lint --fix","lint:fix:md":"prettier --write **/*.md"},"keywords":["bottender","proposal","conversation"],"license":"MIT","dependencies":{"debug":"^4.1.1","invariant":"^2.2.4","lodash":"^4.17.15"},"devDependencies":{"eslint":"^7.0.0","eslint-config-yoctol-base":"^0.23.0","eslint-plugin-import":"^2.20.2","eslint-plugin-prettier":"^3.1.3","eslint-plugin-sort-imports-es6-autofix":"^0.5.0","prettier":"^2.0.5"},"gitHead":"026b66a7ac462cfe327df11f83db819353599c44","_id":"@bottender/proposal-conversation@0.1.0","_nodeVersion":"13.8.0","_npmVersion":"6.13.4","dist":{"integrity":"sha512-LdW/YQS8MXn9rm/HEVbEqHeiRWkuQ2XA7dzj8guMbS1Hol0Un6GT2Rsp3XUDOLp0w8aFgjPn2AK1VoluVsu9aw==","shasum":"339c3f47cd4b07ccbb190289fbfa5612a0107ee7","tarball":"https://registry.npmjs.org/@bottender/proposal-conversation/-/proposal-conversation-0.1.0.tgz","fileCount":40945,"unpackedSize":177929253,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJew60YCRA9TVsSAnZWagAAl50P/0+utXaA1b/OD4mEMLEz\nYosyQRHWt+4HX2ixIGrQ3AydLUzio8nfuLSkwcvDA4WqTj8Sz7jNzAK4dbTP\ntCDdfYXSb476gHyXkbVE1WEtOZYwYw7E7yVBnB8SVUMCbbBQTYrDZhn2tgJI\nVUmPOHNz0nM8rdrESbolZQ37QboN+ktLB2e3CSFzgw4oZFZC5hAxwFfZ7O9Y\nRRZg2QXZQpMtnlI/QxCyc2iyc6kpa/UZgcILjMFjfKvesMBr00MIWZD0k+V2\nqbJ41DrITLF6kBvFplb3bjzuKoxpnpy+2YiqwXKjAt6x/LlhvLYMVtSukJGJ\nFC5omfgKj8IQdKsIMka8yOuIRtb+QBRV4itX1Rqp8LhWdnbBglcUTJ7v3w/x\n3fToEzl9NU9lrozs5yN//I96FCz7QImHErgjBX0TL0EuwT2nYiiXfjwDCC27\nIsg2/FMHcH/luEzFdZexW2DxGitQgXDNv2EBZVwwE/53SSN8o8xSJc1fzmFB\nPx4XXTnlPECGQVRHfDmNtXWROgsScMfaJdLjDoG3rNcwLPCLMEeOKJdGJSpu\nQuFp6O0S/Qc5+1fZS1ZajYu9sxyoQuHSoFUh5XwvZX/glIEFAYFD/qnJz8eu\n0hvh5wUWzGFaR9dC43easJXyRXByh89ozjzhONr2phxB/E6tQif845u3HTV9\nWSj/\r\n=8Jn1\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDlK76PPSHavPSXGI6qrRr3n6joaZuCtO51xtHu/Aqy/AIgeHzZtPuuu+M1eMV0LQ6KIvFSmPXtYHIwFdwv4FMQY3o="}]},"maintainers":[{"name":"chentsulin","email":"chentsulin@gmail.com"}],"_npmUser":{"name":"chentsulin","email":"chentsulin@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/proposal-conversation_0.1.0_1589882134953_0.7588083176581701"},"_hasShrinkwrap":false}},"time":{"created":"2020-05-19T09:55:34.829Z","0.1.0":"2020-05-19T09:55:36.553Z","modified":"2022-04-04T20:15:04.013Z"},"maintainers":[{"email":"wtflink515@gmail.com","name":"link515"},{"email":"tw0517tw@gmail.com","name":"tw0517tw"},{"email":"et284vu065k3@gmail.com","name":"etrexkuo"},{"email":"chentsulin@gmail.com","name":"chentsulin"}],"description":"A candidate of the Bottender conversation module","keywords":["bottender","proposal","conversation"],"license":"MIT","readme":"# bottender-proposal-conversation\n\n> A candidate of the Bottender conversation module\n\n## Installation\n\n```sh\nnpm install @bottender/proposal-conversation\n```\n\nOr \n\n```sh\nyarn add @bottender/proposal-conversation\n```\n\n## Usage\n\nFirst of all, you have to wrap your root `App` entry in the `run` function exported by this package:\n\n```js\nconst { run } = require('@bottender/proposal-conversation');\n\nmodule.exports = run(function App() {\n  // ...\n});\n```\n\nBecause we implemented this proposal outside of the `bottender` package, calling the `run` function is necessary here to extend the default behavior of the Bottender framework.\n\nAfter that you may use the `registerAction` function to register actions which can return a `prompt` call as the return value. By doing so, when the user answers the question, this action is executed again and the input text becomes the props of the action:\n\n```js\nconst { run, registerAction, getAction, prompt } = require('@bottender/proposal-conversation');\n\nregisterAction('AskLikeCheeseOrNot', async function AskLikeCheeseOrNot(\n  context,\n  props\n) {\n  if (!props.result) {\n    await context.sendText('Do you like cheese? (yes/no)');\n    return prompt('result');\n  }\n\n  if (props.result === 'yes') {\n    await context.sendText('You said yes! How wonderful.');\n  } else if (props.result === 'no') {\n    await context.sendText('You said no, that is too bad.');\n  } else {\n    await context.sendText('Sorry I did not understand.');\n  }\n});\n\nmodule.exports = run(function App() {\n  return getAction('AskLikeCheeseOrNot');\n});\n```\n\n## Examples\n\nWe have a bunch of examples in the [examples](https://github.com/Yoctol/bottender-proposal-conversation/tree/master/examples) folder.\n\n## API\n\n### registerAction(name: string, action: Action)\n\nRegister the action.\n\n```js\nconst { registerAction } = require('@bottender/proposal-conversation');\n\nregisterAction('AskLikeCheeseOrNot', async function AskLikeCheeseOrNot(\n  context,\n  props\n) {\n  // ...\n});\n```\n\n> **Note:** You must call `registerAction` before calling the `getAction` function, so we recommend putting them on the top of the `index.js` or `src/index.js` file.\n\n### getAction(name: string)\n\nGet the registered action by the name.\n\n```js\nconst { getAction } = require('@bottender/proposal-conversation');\n\nconst action = getAction('AskLikeCheeseOrNot');\n```\n\n### prompt(key: string)\n\n```js\nconst { prompt } = require('@bottender/proposal-conversation');\n```\n\n> **Note:** `prompt` can only be used inside the registered action.\n\n### setField(context: Context, field: string, value: any)\n\nSet the value of the field.\n\n```js\nconst { setField } = require('@bottender/proposal-conversation');\n\nregisterAction('AskName', async function AskName(context, props) {\n  if (!props.name) {\n    await context.sendText('Please type your name:');\n    return prompt('name');\n  }\n\n  let name = props.name;\n  if (props.name.length > 30) {\n    name = `${props.name.slice(0, 27)}...`;\n    setField(context, 'name', name);\n    await context.sendText(\n      `Name can't be more than 30 characters. Set your name to ${name}`\n    );\n  }\n\n  // ...\n});\n```\n\n> **Note:** `setField` can only be used inside the registered action.\n\n### deleteField(context: Context, field: string | string[])\n\nDelete the value of the field.\n\n```js\nconst { deleteField } = require('@bottender/proposal-conversation');\n\nregisterAction('AskNameAndPhone', async function AskNameAndPhone(context, props) {\n  if (!props.name) {\n    await context.sendText('Please type your name:');\n    return prompt('name');\n  }\n\n  if (!props.phone) {\n    await context.sendText('Please type your phone number:');\n    return prompt('phone');\n  }\n\n  if (!props.confirm) {\n    await context.sendText(\n      `${props.name}, your phone number is ${props.phone}, right? If not, which part you want to refill? (yes|name|phone)`\n    );\n    return prompt('confirm');\n  }\n\n  if (props.confirm === 'yes') {\n    await context.sendText(\n      `Thank you for your help, your personal data was stored correctly.`\n    );\n  } else if (props.confirm === 'name') {\n    deleteField(context, ['name', 'confirm']);\n    await context.sendText('Please retype your name:');\n    return prompt('name');\n  } else if (props.confirm === 'phone') {\n    deleteField(context, ['phone', 'confirm']);\n    await context.sendText('Please retype your phone again:');\n    return prompt('phone');\n  } \n});\n```\n\n> **Note:** `deleteField` can only be used inside the registered action.\n\n### run(action: Action)\n\nThe extension of the runner in the Bottender framework.\n\n```js\nmodule.exports = run(function App() {\n  // ...\n});\n```\n","readmeFilename":"README.md"}