Bots & AI

Fortune Teller Chatbot

Basis for a chat bot.
Back to BLOCKS

About Fortune Teller Chatbot

This block makes Zoltar, a simple fortune teller chat bot that will respond to a user's questions with a 'magic 8 ball' like response.

Try it Now
Categories:
Bots & AI Bots & AI
Bots & AI
Bots & AI
Chat & Social
Chat & Social
Triggers & Notifications
Triggers & Notifications
Last Updated:
20160801 at 17:53:49
Author:
Ian Jennings

Walkthrough

This bot responds to questions asked in the channel. First, an array of responses is defined at the top.

var responses = [
    'It is certain.',
    'It is decidedly so.',
    'Without a doubt.'
    //...
]

Then, the script checks to see if a question was asked by making sure a question mark (?) appears within the message.

If it does not exist, the bot asks the user to ask a question. If it does exist, the bot calculates a response using the question length. This ensures that the same question is met with the same answer.

Input

An example message published by the client Input Channel: advice-channel
"Is PubNub Blocks the best thing ever?"

Output

A message will be published on the same channel Output Channel: advice-channel
"It is decidedly so."

Try PubNub Today

Connect up to 100 devices for Free