paint-brush
ReaderBot: An Event Driven ChatBotby@init_27
483 reads
483 reads

ReaderBot: An Event Driven ChatBot

by Sanyam BhutaniApril 11th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

This post discusses the Event Driven <a href="https://hackernoon.com/tagged/programming" target="_blank">Programming</a> Paradigm.

Company Mentioned

Mention Thumbnail

Coin Mentioned

Mention Thumbnail
featured image - ReaderBot: An Event Driven ChatBot
Sanyam Bhutani HackerNoon profile picture

This is Part 4 in the ‘Diary of a Flying Car Engineer’ Series

This post discusses the Event Driven Programming Paradigm.

Photo by rawpixel.com on Unsplash

Event Driven Programming

Event-driven programming is a programming paradigm in which the flow of the program is determined by events.

  • There is a loop constantly listening to callbacks.
  • For a given callback, a state transition might occur.
  • Listener() Resumes.

How is Event Driven Programming different from Standard Programming paradigm?

  • Event Driven is based on Events unlike a program with a fixed flow.
  • It can have different possible outcomes during execution based on the interaction with environment and events that occur.

EDP in Flying Cars:

  • Flights are dynamic.
  • Allows response to different changes in Environment.
  • Allows re-planning in real flight time.

Explanatory Example

Below, is the code for ReaderBot: A EDP based chatbot that interacts with you and opens articles that you’d like to read based on your responses.

Feel free to check the GH repository. Below, is the explanation of the key functions.


init27/ReaderBot_Contribute to ReaderBot development by creating an account on GitHub._github.com

Steps:


  • Register Callbacks:Maintain a local copy of responses to callbacks.

For Example, consider a callback for Self Driving Cars.

This is a callback that the Bot is expected to execute when provided an input of “SDCs”


self.register_callback("Self Driving Cars",self.respond_to_sdc)

We have to populate a local dictionary for accepted messages for the pre-defined responses, such as the SDC callback shown above.







def register_callback(self, message, callback):"""Registers a callback to a message."""if message not in self.accepted_messages:self.accepted_messages[message] = []self.accepted_messages[message].append(callback)

Here, We’re creating a local dictionary of accepted messages for standard responses.


  • Registering specific actions:If you want to read something on Self Driving Cars, You’d expect the ReaderBot to call a SDC callback.


def respond_to_sdc(self):webbrowser.open_new("https://hackernoon.com/a-self-driving-new-year-33284e592f35")

This would open in a new tab, a post on Self Driving Cars.

Next up, is extending EDP to the Flying Car World and programming Flight Plan for an Autonomous Drone.

Checkout the Video for My First Project of the Flying Car Nanodegree, completely based on EDP here:

If you found this article interesting and would like to stay in touch, you can find me on Twitter here.