Skip to content

Instantly share code, notes, and snippets.

View makefunstuff's full-sized avatar
😇
Why?

Bye Github makefunstuff

😇
Why?
View GitHub Profile
Bot.on :message do |message|
if message.quick_reply && message.quick_reply.match?('time')
message.reply(text: 'Thank you I will notify you very soon, have a good and productive day!')
end
if message.quick_reply && message.quick_reply == 'setup_started'
User.find_or_create_by(facebook_id: message.sender['id'])
message.reply(
text: 'When should I ask you about your day?',
Bot.on :postback do |postback|
case postback.payload
when 'SETUP_BOT'
postback.reply(
text: 'Hello, I am your personal lifelog assistant, let me help you with setup procedure',
quick_replies: [
{
content_type: 'text',
title: 'I want to set you up',
payload: 'setup_started'
Bot.on :postback do |postback|
case postback.payload
when 'SETUP_BOT'
postback.reply(text: 'Hello, I am your personal lifelog assistant, let me help you with setup procedure')
when 'RESET'
# TODO: we will implement reset functionality soon
postback.reply(text: 'Reset has been completed')
else
Rails.logger.warn('Unhandled postback')
class CreateUpdates < ActiveRecord::Migration[5.0]
def change
create_table :updates do |t|
t.integer :user_id
t.integer :mood
t.text :message
t.timestamps
end
end
class CreateUsers < ActiveRecord::Migration[5.0]
def change
create_table :users do |t|
t.string :facebook_id
t.datetime :notification_time
t.timestamps
end
end
end
class Update < ApplicationRecord
enum mood: [:good, :normal, :bad]
belongs_to :user
end
class User < ApplicationRecord
has_many :updates
end
namespace :bot_setup do
desc 'Create get started button'
task get_started_button_create: :environment do
Facebook::Messenger::Thread.set({
setting_type: 'call_to_actions',
thread_state: 'new_thread',
call_to_actions: [
{
payload: 'SETUP_BOT'
}
require 'facebook/messenger'
include Facebook::Messenger
Bot.on :message do |message|
message.id # => 'mid.1457764197618:41d102a3e1ae206a38'
message.sender # => { 'id' => '1008372609250235' }
message.seq # => 73
message.sent_at # => 2016-04-22 21:30:36 +0200
message.text # => 'Hello, bot!'
Rails.application.routes.draw do
mount Facebook::Messenger::Server, at: 'webhooks/messenger'
end