Skip to content
David Mann edited this page Sep 24, 2016 · 13 revisions

Welcome to the botstack wiki!

!Work in progress!

You can find the Bot logic in lib/bot. Put your main Logic into bot_logic.rb - you can use different modules to speed up your bot development.

#BASIC USAGE Put all your logic into lib/bot. We've already prepared everything for you to kickstart your project.

@fb_params holds @request_type holds the type of the request. Could be one of the following:

  • DELIVERY (maybe will be removed in the future, to disruptive)
  • OPTIN
  • CALLBACK
  • TEXT
  • IMAGE -> @fb_params has the url to the image
  • LOCATION-> @fb_params has the long / lat
  • AUDIO -> @fb_params has the url to the mp3 file
  • ATTACHMENT_UNKNOWN -> @fb_params has the url to the ATTACHMENT_UNKNOWN (mostly http links fucked up with fb outbound link system) @current_user hold infos of your current user (last seen, state machine, user id ...)

#MODULES

Reply Module

This function will reply a message back to the user who sent one. you can use Spintax and Emojs.

 def reply_message(msg, options={})

 def example()
  reply_message "make {:pizza:|:sushi:|:lemon:} great again!"
 end

This function will send an image back to the user who sent a message to your bot.

 def reply_image(img_url)

This function will render HTML and send an image back to the user who sent a message to your bot.

 def reply_html(html)

This function will render a bubble and send it to the user.

 def reply_bubble

This function will return a string containing the message a user sent to your bot.

 def get_message

Emoji Module

Most of the time you will not need the Emoji Module because it is already integrated into the reply module.

This function will return the UTF-8 representation of the given Emoji Name

 def get_emoji(name)

This function will send a reply message with the UTF-8 representation of the given Emoji Name

 def reply_emoji(name)

This function will be always used with the reply_message function of the repy module. It will search for emoji names surrounded with : and replaces them with the UTF-8 representation of the given [Emoji Name]

 def compute_emojis(content)

This function is the opposite of the function above.

 def parse_emojis(content)

Web Search Module

With the web search module you can transport websites to messengers. Just add two methods to your bot logic. One for handling search requests and one for handling user input on the search results.

search_request_on_website(
	url: "http://www.example.com/",
	form_name: 'search',
	result_css_selector: '.result > a',
	image_css_selector: 'img',
	button_text: 'more infos'
)

handle_search_result(
	url: "http://www.example.com",
	result_css_selector: ".result"
)

State Machine Module

This Module will help you with guiding users through different states of your bot.

Example usage of the State Machine Module:

class BotLogic < BaseBotLogic

	def self.bot_logic
		state_action 0, :greeting
		state_action 1, :turorial
		state_action 2, :bye
	end

	def self.greeting
		reply_message "greeting"
		state_go
	end 

	def self.turorial
		reply_message "turorial"
		state_go
	end 

	def self.bye
		reply_message "bye"
		state_reset
	end 

end

Broadcast Module

This Module will Broadcast to either all users or the ones who subscribed a specific list. You can call the blacklist function to allow unsubscribing from notifications.

   #--> self.handle_blacklist
   #--> self.broadcast_all
   #--> self.broadcast_list
   #--> self.offer_subscription
   #--> self.handle_subscription_response

User Roulette Module

This Module will create random 1:1 connections between your users.

   #--> self.roulette_message
   #--> self.handle_roulette_messege_response

Browser Module

This Module can be used for Browser emulation.

   #--> self.
   #--> self.

CSV Lookup Module

This Module will lookup the search string and will return the best match.

   #--> Google Spreadsheet Lookup Module

Question Module

This Module allows you to create somethign similar to web forms on the internet. The bot will ask a set of questions and can compute a answer based on the search questions.

   #--> self.ask_questions
   #--> self.compute_answer