Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1619 from botpress/ya-refactor-channelweb
chore(channel-web): refactoring
- Loading branch information
Showing
60 changed files
with
2,278 additions
and
3,081 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
examples/custom-component/src/hooks/after_incoming_middleware/advanced.js
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,63 @@ | ||
if (event.preview === 'disappearKeyboard') { | ||
const payload = { | ||
type: 'custom', | ||
module: 'feedback', | ||
component: 'DisappearingText', | ||
myrandomproperty: | ||
'This text will disappear when the timer expires. You can add any component, buttons, etc as a keyboard', | ||
wrapped: { | ||
// We can wrap an existing component | ||
...event.payload | ||
} | ||
} | ||
bp.events.replyToEvent(event, [payload]) | ||
} | ||
|
||
if (event.preview === 'feedbackKeyboard') { | ||
const payload = { | ||
type: 'custom', | ||
module: 'feedback', | ||
component: 'FeedbackButtons', | ||
wrapped: { | ||
// Wrap an existing event... | ||
...event.payload, | ||
|
||
// Or create a new one | ||
type: 'text', | ||
text: 'bla' | ||
} | ||
} | ||
bp.events.replyToEvent(event, [payload]) | ||
} | ||
|
||
if (event.preview === 'multiLineKeyboard') { | ||
const payload = { | ||
type: 'text', | ||
text: 'how can i help you?', | ||
quick_replies: [ | ||
[{ label: 'row 1, button 1', payload: 'something' }, { label: 'row 1, button 2', payload: 'something' }], | ||
[{ label: 'row 2, button 1', payload: 'something' }], | ||
[{ label: 'row 3, button 1', payload: 'something' }] | ||
] | ||
} | ||
bp.events.replyToEvent(event, [payload]) | ||
} | ||
|
||
if (event.preview === 'wrapperExample') { | ||
const payload = { | ||
type: 'custom', | ||
module: 'feedback', | ||
component: 'ColorText', | ||
color: '#ff0000', | ||
wrapped: { | ||
type: 'custom', | ||
module: 'feedback', | ||
component: 'UpperCase', | ||
wrapped: { | ||
type: 'text', | ||
text: 'this will be colored red & in uppercase ' | ||
} | ||
} | ||
} | ||
bp.events.replyToEvent(event, [payload]) | ||
} |
61 changes: 61 additions & 0 deletions
61
examples/custom-component/src/views/lite/components/Advanced.jsx
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,61 @@ | ||
import React from 'react' | ||
|
||
export class DisappearingText extends React.Component { | ||
state = { | ||
visible: true | ||
} | ||
componentDidMount() { | ||
// Text disappear in 5 seconds. You can also get the date the message was sent by using this.props.sentOn | ||
setTimeout(() => { | ||
this.setState({ visible: false }) | ||
}, 5000) | ||
} | ||
|
||
render() { | ||
const Keyboard = this.props.keyboard | ||
|
||
// Prepent to add something before the composer, and Append to add after | ||
return ( | ||
<Keyboard.Prepend keyboard={this.props.myrandomproperty} visible={this.state.visible}> | ||
This text is always visible in the chat window | ||
</Keyboard.Prepend> | ||
) | ||
} | ||
} | ||
|
||
export class FeedbackButtons extends React.Component { | ||
sendSatisfied = () => { | ||
this.props.onSendData({ payload: { type: 'user_satisfied', text: 'satisfied' } }) | ||
} | ||
|
||
sendMoreInfo = () => { | ||
this.props.onSendData({ payload: { type: 'more_info', text: 'more info about ...' } }) | ||
} | ||
|
||
renderBtn() { | ||
return ( | ||
<div> | ||
<button onClick={this.sendSatisfied}>I am satisfied</button> | ||
<button onClick={this.sendMoreInfo}>I need more info</button> | ||
</div> | ||
) | ||
} | ||
|
||
// This simple example will show two buttons after the bot's answer (only the latest one) asking for feedback | ||
render() { | ||
const Keyboard = this.props.keyboard | ||
return ( | ||
<Keyboard.Append keyboard={this.renderBtn()} visible={this.props.isLastGroup}> | ||
{this.props.children} | ||
</Keyboard.Append> | ||
) | ||
} | ||
} | ||
|
||
export const ColorText = props => { | ||
return <div style={{ color: props.color }}>{props.children}</div> | ||
} | ||
|
||
export const UpperCase = props => { | ||
return <div style={{ textTransform: 'uppercase' }}>{props.children}</div> | ||
} |
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
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.