Giter Club home page Giter Club logo

botstack's Introduction

botstack

botstack-logo

This is a base project for creating FB Chatbots. It has a state machine and User Management and allows you to add functionality with modules.

Quickstart

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

@msg_meta 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 -> @msg_meta has the url to the image
  • LOCATION-> @msg_meta has the long / lat
  • AUDIO -> @msg_meta has the url to the mp3 file
  • ATTACHMENT_UNKNOWN -> @msg_meta 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 ...)

botstack grafik-x

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 along with a set of button options specified in an array.

 def reply_quick_buttons(msg, options=%W(Yes No))

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

Installation

clone the repo copy config/settings.yml to settings.local.yml and enter your api keys use ngrok or another vpn to tunnel your connection run the following commands

bundle install
rails s

set the webhook to https://tunnel_url/bot and use your token (default: github)

Contributing

  • Fork it!
  • Create your feature branch: git checkout -b my-new-feature
  • Commit your changes: git commit -am 'Useful information about your new features'
  • Push to the branch: git push origin my-new-feature
  • Submit a pull request on the Development branch :D

gems used

botstack's People

Contributors

davidmann4 avatar mraaroncruz avatar hola-soy-milk avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.