Back to Parent

Product

All of Frasier bots responses are either based on his favorites things or they are dog-centric. So all of this gifs are either favorite things like food and Bob's Burgers or dog gifs. All of this jokes are dog jokes as well, which they are all really corny jokes. As I mentioned earlier, I wanted to use the giphy api but I had a lot of issues trying to incorporate it into my code correctly, so I had to figure out another way to incorporate gifs. So I decided to incorporate specific gifs into the responses I wrote, so I would still have the gifs to add to the fun personality that I wanted my Frasier bot to have. (see code below). Another thing I included was code that would have the chatbot search for keywords in the conversation and send replies based on those keywords. By having this it would not require the user to write an exact phase and allow the conversation to feel more fluid like you are talking to a friend. So for example with the code below, instead of requiring the user to write just "movie," the user could write "What is your favorite movie?" and the bot would see the keyword "movie" and then send the response.

Example of code I used:

elsif body.include?("movie")
message = "I love Ratatouille"
media = "https://media.giphy.com/media/xKggUfdA60O6A/giphy.gif"

I also incorporated jokes, which I started with the basic joke code from the skillsdev assignment. I wanted to make it more of a back and forth interaction, which I tried to figure out through google but was unsuccessful. So with the help from Daragh, I was able to apply the correct code to get the joke interaction I wanted. It incorporated sessions and .split('\n') which would split a single sentence into multiple parts. In addition, I noticed that the facts I had, while they were random in their response they would repeat sometimes, so I decided to apply the same session principle I used in the jokes section to my facts section. 

Code I used:

What kind of dog does Dracula 🧛🏻‍♂️ have?\n A bloodhound! 
elsif body.include?("joke")
array_of_lines = IO.readlines("jokes.txt")
# store the selected joke in a session
session["current_joke"] = array_of_lines.sample
# choose the first part of this: the question

# and send it to the user
message = session["current_joke"].split('\n')[0]
elsif not session["current_joke"].nil?
# if there's a joke on the go...
# and they've replied
message = session["current_joke"].split('\n')[1]
# clear the joke...
session["current_joke"] = nil

elsif body.include?("fact") || body.include?("yourself")
array_of_lines = IO.readlines("facts.txt")
# store the selected fact in a session
session["current_fact"] = array_of_lines.sample
# and send it to the user

message = session["current_fact"]

Heroku App Link: https://sheltered-retreat-11154.herokuapp.com
Frasier bot #: (813)-670-8710


Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0