This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Update < ApplicationRecord | |
enum mood: [:good, :normal, :bad] | |
belongs_to :user | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ApplicationRecord | |
has_many :updates | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
mount Facebook::Messenger::Server, at: 'webhooks/messenger' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'boot' | |
require "rails" | |
# Pick the frameworks you want: | |
require "active_model/railtie" | |
require "active_job/railtie" | |
require "active_record/railtie" | |
require "action_controller/railtie" | |
require "action_mailer/railtie" | |
require "action_view/railtie" |