How to Build a Smart Chatbot Assistant with ChatEngine and IBM Watson Assistant

Pubnub coupled with IBM Watson can enable developers and business owners to streamline their frontlines by creating smart assistants which answers the simple questions for you.

Syed Ahmed
Jun 12, 2018 · 9 min read
Image for post
Image for post

How It Works 👩‍💻

Image for post
Image for post

Getting Started with ChatEngine and Watson


Configuring ChatEngine 🚒

Watson + BLOCKS 🍫

Image for post
Image for post
Image for post
Image for post

Me, My Bot, and I 🤖

$ npx create-react-app Watson-Assistan
cd Watson-Assistant/
|-- Watson-Assistant 
|-- .gitignore
|-- README.md
|-- package-lock.json
|-- package.json
|-- public
| |-- favicon.ico
| |-- index.html
| |-- manifest.json
|-- src
|-- App.css
|-- App.js
|-- App.test.js
|-- index.css
|-- index.js
|-- logo.svg
|-- registerServiceWorker.js
|-- Watson-Assistant 
|-- .gitignore
|-- package-lock.json
|-- package.json
|-- public
| |-- favicon.ico
| |-- index.html
| |-- manifest.json
|-- src
|-- index.css
|-- index.js
$ npm i chat-engine
const ChatClient = ChatEngineCore.create({ 
publishKey: 'pub-c-e1295433-4475-476d-9e37-4bdb84dacba0', subscribeKey: 'sub-c-890a0b26-6451-11e8-90b6-8e3ee2a92f04'
},{
globalChannel: 'watson-assistant'
});
const now = new Date().getTime(); const username = ['user', now].join('-');
ChatClient.connect(username, { signedOnTime: now }); ChatBot.connect(`${now}bot`, { signedOnTime: now });
constructor() { super(); this.chat = new ChatClient.Chat(`${now}chat`); 
this.bot = new ChatBot.Chat(`${now}chat`);
this.state = {
reply: 'Ask Me Something!',
chatInput: '',
animation: 'Congratulate' };
}
render() { 
return (
<div style={container}>
<div style={{height:100, width:100}}>
<p> {this.state.reply} </p>
<Clippy
actor={ 'Clippy' }
animation={ this.state.animation } />
<input
id = "chat-input"
type = "text"
name = ""
value = { this.state.chatInput }
onChange = { this.setChatInput }
onKeyPress = { this.handleKeyPress } />
<input
type = "button"
onClick = { this.sendChat }
value = "Send Chat" />
</div>
</div> ); }
sendChat = () => { 
if (this.state.chatInput) {
this.chat.emit('message', {
text: this.state.chatInput,
channel: `${now}chat`
});
this.setState({ chatInput: '' })
this.setState({ animation: 'Processing', reply: '' }); }
}
componentDidMount() {
this.bot.on('message', (payload) => { axios.get(`https://pubsub.pubnub.com/v1/blocks/sub-key/sub-c-890a0b26-6451-11e8-90b6-8e3ee2a92f04/chat? question=${payload.data.text}`) .then(response => { this.setState({ animation: 'Writing', reply: response.data }); });
});
}
Image for post
Image for post
ChatClient.on('$.ready', () => { 
ChatBot.on('$.ready', () => {
ReactDOM.render( <Chat /> , document.getElementById('root') ); });
});

Our Chatbot is Up-and-Running! 🏃‍

Follow me on Twitter / Instagram! @nxsyed


HackerNoon.com

#BlackLivesMatter

Sign up for DONT SIGN UP FOR THIS NEWSLETTER

By HackerNoon.com

how hackers start their afternoon. the real shit is on hackernoon.com. Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Syed Ahmed

Written by

Software developer

HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Syed Ahmed

Written by

Software developer

HackerNoon.com

Elijah McClain, George Floyd, Eric Garner, Breonna Taylor, Ahmaud Arbery, Michael Brown, Oscar Grant, Atatiana Jefferson, Tamir Rice, Bettie Jones, Botham Jean

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store