Skip to content
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
bb5cc38
add: commits from another branch that was done
imOscarCrespo Aug 22, 2019
cb39245
fix: remove consoles
imOscarCrespo Aug 22, 2019
b4a9821
fix(docu): two typos errors and two broken links
guinii Aug 22, 2019
cb3fea4
refactor: reduction code with same functionality && area of the butto…
imOscarCrespo Aug 23, 2019
dbc459c
chore(deps): bump node-nlp from 3.4.0 to 3.6.0 (#200)
dependabot-preview[bot] Aug 26, 2019
15e1677
chore(deps): bump aws-sdk from 2.513.0 to 2.517.0 (#201)
dependabot-preview[bot] Aug 26, 2019
27c96a5
chore(deps-dev): bump eslint-plugin-jest from 22.15.0 to 22.15.2 (#195)
dependabot-preview[bot] Aug 26, 2019
860717c
chore(deps): bump @types/jest from 24.0.17 to 24.0.18 (#193)
dependabot-preview[bot] Aug 26, 2019
c64b5d7
chore(deps-dev): bump @types/node from 12.7.1 to 12.7.2 (#185)
dependabot-preview[bot] Aug 26, 2019
1399b99
chore(deps-dev): bump core-js from 3.2.0 to 3.2.1 (#179)
dependabot-preview[bot] Aug 26, 2019
0259c57
chore(deps-dev): bump react-hot-loader from 4.12.10 to 4.12.11 (#176)
dependabot-preview[bot] Aug 26, 2019
d1a7071
Contentful/fix reply buttons (#149)
dpinol Aug 26, 2019
1575860
chore(core/react): improve typing for CoreBot and add for NodeApp
dpinol Jul 29, 2019
9a2cb5c
chore(core/react) bump to 0.9.0-alpha.7
dpinol Jul 30, 2019
822e009
chore(contentful): release 0.9.13 with sdk-capabilities
dpinol Jul 31, 2019
39af7b5
chore(dynamo): release 0.9.11 with sdk-capabilities
dpinol Jul 31, 2019
f7fe881
feature(contenful): 0.9.14 support keywords with only 1 stopword
dpinol Jul 31, 2019
bef346b
chore(contenful): prepare for using Spanish snowball stemmer
dpinol Jul 31, 2019
9d63708
chore(contenful): hola/hi added as stopword
dpinol Aug 6, 2019
d1622a6
chore(contenful): 0.9.15 test search when 2 contents share the same k…
dpinol Aug 6, 2019
d72d4e3
refactor: sendInput function refactorized for not repeating code
imOscarCrespo Aug 23, 2019
998c328
feat: change variable name of the map
imOscarCrespo Aug 26, 2019
a6f9bae
feat: change persistent menu on render in dev-app
imOscarCrespo Aug 26, 2019
de7b9e8
fix: second parameter of map deleted
imOscarCrespo Aug 26, 2019
8a5833d
add: commits from another branch that was done
imOscarCrespo Aug 22, 2019
1501d99
fix: remove consoles
imOscarCrespo Aug 22, 2019
a023db0
refactor: reduction code with same functionality && area of the butto…
imOscarCrespo Aug 23, 2019
bdb8b39
merge with master
imOscarCrespo Aug 26, 2019
c07fcd4
fix: remove isRegex variable, never used
imOscarCrespo Aug 26, 2019
73e2e4a
fix: remove function that was created only for testing
imOscarCrespo Aug 26, 2019
e3900d1
add: commits from another branch that was done
imOscarCrespo Aug 22, 2019
93f5f2e
fix: remove consoles
imOscarCrespo Aug 22, 2019
663aa16
refactor: reduction code with same functionality && area of the butto…
imOscarCrespo Aug 23, 2019
59b2215
add: commits from another branch that was done
imOscarCrespo Aug 22, 2019
c74aa68
fix: remove consoles
imOscarCrespo Aug 22, 2019
56920f7
Merge branch 'persistentMenuBotonic' of github.com:hubtype/botonic in…
imOscarCrespo Aug 26, 2019
ce08f84
add: commits from another branch that was done
imOscarCrespo Aug 22, 2019
7294ace
fix: remove consoles
imOscarCrespo Aug 22, 2019
656fc70
refactor: reduction code with same functionality && area of the butto…
imOscarCrespo Aug 23, 2019
cd40dd2
add: commits from another branch that was done
imOscarCrespo Aug 22, 2019
4139112
fix: remove consoles
imOscarCrespo Aug 22, 2019
2933f70
fix: remove isRegex variable, never used
imOscarCrespo Aug 26, 2019
bcd0e2c
add: commits from another branch that was done
imOscarCrespo Aug 22, 2019
817a8d4
fix: remove consoles
imOscarCrespo Aug 22, 2019
4922212
add: commits from another branch that was done
imOscarCrespo Aug 22, 2019
8833455
fix: remove consoles
imOscarCrespo Aug 22, 2019
9709d23
merge
imOscarCrespo Aug 26, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ node_modules/
tmp/
.DS_Store
yarn.lock
.yarn-metadata.json
.nyc_output/
dist/
tmp/
.yalc/
yalc.lock
.eslintcache
69 changes: 33 additions & 36 deletions docs/2.getting-started/2.creating-your-first-bot.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ menu: 2. Getting Started

import { NextButton } from '../components/nextButton.tsx'


# **Creating Your First Bot**

Now that you have [Botonic and its dependencies installed](/getting-started/installation), you can build your first bot!
Expand All @@ -29,19 +28,19 @@ To start a new bot, open your terminal/command prompt and run:
botonic new testBot blank
```

* `new` will tell the CLI to create a new bot.
* `testBot` will be the directory name for your project.
* `blank` will be the starter template for your project.
- `new` will tell the CLI to create a new bot.
- `testBot` will be the directory name for your project.
- `blank` will be the starter template for your project.

Along with creating your project, this will also install node modules for the application, and make the first build.

Along with the blank template, Botonic also provides the following official templates:

* `tutorial`: a bot that explains you some basic concepts in Botonic. This template has lots of comments in its code so you can learn by reading through the source files.
* `childs`: a simple example on how `childRoutes` works.
* `dynamic_carousel`: a bot that gets data from an external API and renders a Carousel (see: [RCML](/main-concepts/rich-conversational-markup-language)).
* `handoff`: a simple bot that transfer the conversation into Hubtype Desk. (see: [human handOff](/tutorials-and-examples/human-handoff))
* `intent`: a bot that use external AI like DialogFlow.
- `tutorial`: a bot that explains you some basic concepts in Botonic. This template has lots of comments in its code so you can learn by reading through the source files.
- `childs`: a simple example on how `childRoutes` works.
- `dynamic_carousel`: a bot that gets data from an external API and renders a Carousel (see: [RCML](/main-concepts/rich-conversational-markup-language)).
- `handoff`: a simple bot that transfer the conversation into Hubtype Desk. (see: [human handOff](/tutorials-and-examples/human-handoff))
- `intent`: a bot that use external AI like DialogFlow.

If you don’t specify a template at the start, you will be prompted to pick one.

Expand All @@ -53,19 +52,20 @@ Now, you can `cd` into the folder that was created. To get a quick preview of yo
cd testBot
botonic serve
```
*If you are running windows use `npm run start` instead of `botonic serve`*

_If you are running windows use `npm run start` instead of `botonic serve`_

This will give you a local browser url where you can have a chat session with your bot. Just type any text and press enter to send a message to the bot. If you started with the "blank" template the bot will always respond with "I don't understand you".

## Project Structure

* `routes.js`: Here you'll define routes, which maps user inputs and payloads to actions. You can use imported subroutes from other files.
* `integrations.js`: Define your integrations keys with 3rd party services, like NLP platforms.
* `locales`: Locales are objects from which your bot takes your multilanguage definitions. This is useful if you want that your bot addresses to different audiences. The `locales/index.js` file is where all the languages are imported.
* `webviews`: Webviews are small web pages that pop up in the middle of the conversation flow. This lets you offer experiences and features that might be difficult to offer with message bubbles, such as picking products to buy, seats to book, or dates to reserve.
* `actions`: Actions are the units of logic that your bot can perform and where the responses of your bot are defined. You are free to organize them into subdirectories.
* `assets`: Assets is where you can store all the media required for your bot.
* `...`: The rest of the files are needed for the [babel](https://babeljs.io/) and [Botonic](https://github.com/hubtype/botonic) project configuration. We suggest you to not modify its contents, and if not, it's at your own risk!
- `routes.js`: Here you'll define routes, which maps user inputs and payloads to actions. You can use imported subroutes from other files.
- `integrations.js`: Define your integrations keys with 3rd party services, like NLP platforms.
- `locales`: Locales are objects from which your bot takes your multilanguage definitions. This is useful if you want that your bot addresses to different audiences. The `locales/index.js` file is where all the languages are imported.
- `webviews`: Webviews are small web pages that pop up in the middle of the conversation flow. This lets you offer experiences and features that might be difficult to offer with message bubbles, such as picking products to buy, seats to book, or dates to reserve.
- `actions`: Actions are the units of logic that your bot can perform and where the responses of your bot are defined. You are free to organize them into subdirectories.
- `assets`: Assets is where you can store all the media required for your bot.
- `...`: The rest of the files are needed for the [babel](https://babeljs.io/) and [Botonic](https://github.com/hubtype/botonic) project configuration. We suggest you to not modify its contents, and if not, it's at your own risk!

## Adding basic functionality to your bot

Expand All @@ -78,14 +78,12 @@ The first step is to create a route that captures any text. Edit your `src/route
```javascript
import Echo from './actions/echo'

export const routes = [
{path: 'echo', text: /^.+$/, action: Echo}
]
export const routes = [{ path: 'echo', text: /^.+$/, action: Echo }]
```

* `path: 'echo'` means the path that the bot flow has taken.
* `text: /^.+$/` means that this route will capture any text that matches this regular expression.
* `action: "echo"` means that when a user input is matched by this rule, the action named "echo" (that we're going to create in the next step) will be triggered.
- `path: 'echo'` means the path that the bot flow has taken.
- `text: /^.+$/` means that this route will capture any text that matches this regular expression.
- `action: "echo"` means that when a user input is matched by this rule, the action named "echo" (that we're going to create in the next step) will be triggered.

### Create an action

Expand All @@ -106,16 +104,17 @@ export default class extends React.Component {

This is the code that will be executed when the user types anything. As you can see, this is just a React component.

* `render`: this is where you construct the answer of your bot. In this example we return just one message 'Text' whose content is the user input. This data is stored in the variable `context.input.data`.
- `render`: this is where you construct the answer of your bot. In this example we return just one message 'Text' whose content is the user input. This data is stored in the variable `context.input.data`.

> ### NOTE:
> Usually the `render` method spits out HTML code in a typical React project. However, this is sent to messaging platforms like Whatsapp or Facebook Messenger so sending HTML won't work. We've created this HTML-like language called [Rich Conversational Markup Language (RCML)](/api/rich-conversational-markup-language) to help you construct the bot response in a dynamic way.
>
> Usually the `render` method spits out HTML code in a typical React project. However, this is sent to messaging platforms like Whatsapp or Facebook Messenger so sending HTML won't work. We've created this HTML-like language called [Rich Conversational Markup Language (RCML)](/main-concepts/rich-conversational-markup-language) to help you construct the bot response in a dynamic way.

Now try to execute `botonic serve` again and type "hello world" 😊

## Adding Natural Language Understanding

You can go a long way capturing user inputs using regular expressions, but it obviously has its limitations. As you find yourself adding more and more functionality to your bot you get to a point where you need Natural [Language Understanding (NLU)](/api/nlu) capabilities.
You can go a long way capturing user inputs using regular expressions, but it obviously has its limitations. As you find yourself adding more and more functionality to your bot you get to a point where you need Natural [Language Understanding (NLU)](/main-concepts/nlu) capabilities.

NLU lets you capture user inputs by "intent" instead of parsing its raw text. An intent represents all the different ways users can express a unit of meaning that is valid for your bot. For example, you can group the sentences "What's the weather in California?" and "Do you know if it's sunny today in California?" to the intent `get_weather` and the parameter `city=California`. You can then map that intent to an action using a route.

Expand Down Expand Up @@ -153,18 +152,18 @@ import Smalltalk from './actions/smalltalk'
import Echo from './actions/echo'

export const routes = [
{path:'age', intent: "smalltalk.agent.age", action: Age},
{path:'smalltalk', intent: /^smalltalk/, action: Smalltalk},
{path: 'echo', text: /^.+$/, action: Echo}
{ path: 'age', intent: 'smalltalk.agent.age', action: Age },
{ path: 'smalltalk', intent: /^smalltalk/, action: Smalltalk },
{ path: 'echo', text: /^.+$/, action: Echo }
]
```

* `{path:'age', intent: "smalltalk.agent.age", action: Age}` will match exactly the intent "smalltalk.agent.age".
* `{path:'smalltalk', intent: /^smalltalk/, action: Smalltalk}` will match any other "smalltalk" intent.
- `{path:'age', intent: "smalltalk.agent.age", action: Age}` will match exactly the intent "smalltalk.agent.age".
- `{path:'smalltalk', intent: /^smalltalk/, action: Smalltalk}` will match any other "smalltalk" intent.

Routes are checked in order, that's why we put the more specific ones first and the more generic at the end.

Finally, just crete a couple of actions that respond to these intents:
Finally, just create a couple of actions that respond to these intents:

**src/actions/age.js**

Expand All @@ -189,9 +188,7 @@ export default class extends React.Component {
render() {
return (
<>
<Text>
I'm not interested in talking about that...
</Text>
<Text>I'm not interested in talking about that...</Text>
<Image src='https://i.pinimg.com/originals/eb/4d/d1/eb4dd12ae0b4a57a3fbb85e61d0c1cf4.gif' />
</>
)
Expand All @@ -201,4 +198,4 @@ export default class extends React.Component {

That's it! You can run `botonic serve` and play a little bit. Try adding more routes/actions for different Dialogflow intents. When you're ready, go to the next section to learn how to put your bot in production and publish it to messaging platforms like Facebook Messenger.

<NextButton title="Deploying" href="/getting-started/deploying" />
<NextButton title='Deploying' href='/getting-started/deploying' />
34 changes: 17 additions & 17 deletions docs/3.main-concepts/3.rcml.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ In order to create a line break, you new to use `{'\\n'}`.
_Example of how it looks in the Messenger platform:_

<img
src="https://botonic-doc-static.netlify.com/images/buttons.png"
src='https://botonic-doc-static.netlify.com/images/buttons.png'
style={{ display: 'block', margin: 'auto', maxWidth: '50%' }}
/>

Expand All @@ -51,22 +51,22 @@ _Example of how it looks in the Messenger platform:_
<Text>
I will show you three quickreplies. One with a payload, one to go to an action
and another to pass values to that action:
<Reply payload="yes">Cool</Reply>
<Reply path="paradise">Take me to paradise</Reply>
<Reply path="paradise?withfruit=coconut">To a better paradise</Reply>
<Reply payload='yes'>Cool</Reply>
<Reply path='paradise'>Take me to paradise</Reply>
<Reply path='paradise?withfruit=coconut'>To a better paradise</Reply>
</Text>
```

_Example of how it looks in the Messenger platform:_

<img
src="https://botonic-doc-static.netlify.com/images/quickreplies.png"
src='https://botonic-doc-static.netlify.com/images/quickreplies.png'
style={{ display: 'block', margin: 'auto', maxWidth: '60%' }}
/>

> #### NOTE:
>
> Buttons and quickreplies can have an url link, a payload attached, a href attribute, or an action to be triggered. When passing parameters through actions as seen in the example, the data will be accessiblein the field `params` inside the `botonicInit` function.
> Buttons and quickreplies can have an url link, a payload attached, a href attribute, or an action to be triggered. When passing parameters through actions as seen in the example, the data will be accessible in the field `params` inside the `botonicInit` function.

## Carousel

Expand Down Expand Up @@ -129,7 +129,7 @@ export default class extends React.Component {
_Example of how it looks in the Messenger app:_

<img
src="https://botonic-doc-static.netlify.com/images/carrousel.gif"
src='https://botonic-doc-static.netlify.com/images/carrousel.gif'
style={{ display: 'block', margin: 'auto' }}
/>

Expand All @@ -139,17 +139,17 @@ You can send all this types of media files:

```javascript
<>
<Image src="https://botonic.io/images/botonic_react_logo-p-500.png" />
<Video src="https://www.w3schools.com/html/mov_bbb.mp4" />
<Audio src="https://www.w3schools.com/html/horse.mp3" />
<Document src="http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf" />
<Image src='https://botonic.io/images/botonic_react_logo-p-500.png' />
<Video src='https://www.w3schools.com/html/mov_bbb.mp4' />
<Audio src='https://www.w3schools.com/html/horse.mp3' />
<Document src='http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf' />
</>
```

_Example of the media types:_

<img
src="https://botonic-doc-static.netlify.com/images/media_files.png"
src='https://botonic-doc-static.netlify.com/images/media_files.png'
style={{
display: 'block',
margin: 'auto',
Expand All @@ -170,7 +170,7 @@ _Example of the media types:_
_Example in Facebook Messenger:_

<img
src="https://botonic-doc-static.netlify.com/images/doc_location.png"
src='https://botonic-doc-static.netlify.com/images/doc_location.png'
style={{ display: 'block', margin: 'auto' }}
/>

Expand Down Expand Up @@ -223,21 +223,21 @@ export default class extends React.Component {
_This will produce the following output in Facebook Messenger:_

<img
src="https://botonic-doc-static.netlify.com/images/share_1.png"
src='https://botonic-doc-static.netlify.com/images/share_1.png'
style={{ display: 'block', margin: 'auto' }}
/>

_After clicking on it, your defined elements will be displayed:_

<img
src="https://botonic-doc-static.netlify.com/images/share_2.png"
src='https://botonic-doc-static.netlify.com/images/share_2.png'
style={{ display: 'block', margin: 'auto' }}
/>

_This is how it looks on the receiver side:_

<img
src="https://botonic-doc-static.netlify.com/images/share_3.png"
src='https://botonic-doc-static.netlify.com/images/share_3.png'
style={{ display: 'block', margin: 'auto' }}
/>

Expand Down Expand Up @@ -325,7 +325,7 @@ export default class extends React.Component {
_In this case, this template will produce this nice boarding pass._

<img
src="https://botonic-doc-static.netlify.com/images/message_template.png"
src='https://botonic-doc-static.netlify.com/images/message_template.png'
style={{ display: 'block', margin: 'auto' }}
/>

Expand Down
2 changes: 1 addition & 1 deletion packages/botonic-core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/botonic-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@botonic/core",
"version": "0.9.0-alpha.6",
"version": "0.9.0-alpha.7",
"description": "Build Chatbots using React",
"main": "src/index.js",
"scripts": {
Expand Down
23 changes: 19 additions & 4 deletions packages/botonic-plugin-contentful/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ module.exports = {
rules: {
// style. Soon a precommit githook will fix prettier errors
"prettier/prettier": "error",
"filenames/match-regex": [2, "^[a-z-.]+$", true],

"filenames/match-regex": ["warn", "^[a-z-.]+$", true],

// In typescript we must use obj.field when we have the types, and obj['field'] when we don't
// Not set to warn because Webstorm cannot fix eslint rules with --quiet https://youtrack.jetbrains.com/issue/WEB-39246
"dot-notation": "off",

"no-console" :"off",
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
"node/no-unsupported-features/es-syntax": "off", //babel will take care of ES compatibility
"unicorn/no-abusive-eslint-disable" : "off",
"@typescript-eslint/camelcase" : "warn",

// special for TYPESCRIPT
"@typescript-eslint/explicit-function-return-type": "off", // annoying for tests
Expand All @@ -51,13 +51,28 @@ module.exports = {
// allow public functions/classes to call private functions/classes declared below.
// otoh, variables (typically constants) should be declared at the top
"@typescript-eslint/no-use-before-define": ["error", { "variables": true, "functions": false, "classes": false }],
"@typescript-eslint/no-useless-constructor": "warn",
"@typescript-eslint/require-await": "error",
"no-empty-pattern" : "off",
"no-null/no-null": "warn", // fields declared with ? are undefined, not null (be aware that React uses null)
"unicorn/prevent-abbreviations" : "off", // the plugin removes removes type annotations from typescript code :-(
"unicorn/filename-case" : "off", // React convention is in CamelCase
"valid-jsdoc": "off", // function comments hide code complexity (and typescript already have type specifications),

},
"overrides": [
{
"files": [
"tests/**/*.ts" // to be able to skip required fields when not used in a particular test
],
"rules": {
"@typescript-eslint/no-object-literal-type-assertion" : "off",
}
}
],
settings: {
react: {
version: "detect" // Tells eslint-plugin-react to automatically detect the version of React to use
}
},
env: {
jest: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Design
See [diagram](./doc/class-diagram.png). Exported from https://www.draw.io/#G1fMaHqDYF-DsGWC6JrCWvo6f7Psx7Vpzw
See [diagram](/packages/botonic-plugin-contentful/doc/class-diagram.png). Exported from https://www.draw.io/#G1fMaHqDYF-DsGWC6JrCWvo6f7Psx7Vpzw
# Management
## Export
Install cli:
Expand All @@ -11,7 +11,3 @@ Generate personal token from https://app.contentful.com/spaces/p2iyhzd1u4a7/api/
````
contentful space export --space-id=p2iyhzd1u4a7 --management-token=xxx --download-assets
````

## Build

* @babel/runtime must be a dependency in case the plugin is used from a bot packaged with babel-loader
Loading