-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.rb
145 lines (134 loc) · 5.81 KB
/
bot.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
require 'facebook/messenger'
require 'dotenv/load'
include Facebook::Messenger
puts "ENV['ACCESS_TOKEN']: #{ENV['ACCESS_TOKEN']}"
Facebook::Messenger::Subscriptions.subscribe(access_token: ENV["ACCESS_TOKEN"])
Facebook::Messenger::Profile.set({
get_started: {
payload: 'GET_STARTED_PAYLOAD'
}
}, access_token: ENV['ACCESS_TOKEN'])
Facebook::Messenger::Profile.set({
persistent_menu: [
{
locale: 'default',
composer_input_disabled: false,
call_to_actions: [
{
title: 'Buy a book!',
type: 'web_url',
url: "https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=f+scott+fitzgerald",
webview_height_ratio: 'full'
}
]
}
]
}, access_token: ENV["ACCESS_TOKEN"])
def wait_for_user_input
Bot.on :message do |message|
message.mark_seen
puts "Received '#{message.inspect}' from #{message.sender}"
message.typing_on
case message.text
when "Hi", "hi", "hey", "Hey", "Yo", "yo", "hello"
message.reply(text: IDIOMS[:greeting])
message.reply(text: "I imagine you've read my stuff? Which book did you like best?",
quick_replies: [
{
content_type: 'text',
title: 'The Great Gatsby',
payload: 'GREAT_GATSBY'
},
{
content_type: 'text',
title: 'This Side of Paradise',
payload: 'SIDE_PARADISE'
},
{
content_type: 'text',
title: 'Tender is the Night',
payload: 'TENDER_NIGHT'
}
]
)
when "How are you?", "how are you", "how are you?", "how r u", "how r u?"
message.reply(text: IDIOMS[:how_are_you])
when /\sreal\b/
message.reply(text: IDIOMS[:real])
when /\sjoke\b/
message.reply(text: IDIOMS[:joke])
when /\sfortune cookie\b/
message.reply(text: IDIOMS[:fortune_cookie])
when /!{3,}/
message.reply(text: IDIOMS[:exclamation])
when /\sare you working on\b/
message.reply(text: IDIOMS[:working_on])
when /\slook like\b/
message.reply(text: IDIOMS[:look_like])
when /\sdo you believe\b/
message.reply(text: IDIOMS[:believe])
when /\why do you write?\b/
message.reply(text: IDIOMS[:why_write])
when /\sfind a job\b/
message.reply(text: IDIOMS[:help_finding_job])
when /\swrit\w/
message.reply(
attachment: {
type: 'image',
payload: {
url: 'http://www.clivejames.com/files/images/fitzreading.jpg'
}
}
)
message.reply(text: IDIOMS[:writing_great_gatsby])
when /\ssomething pretty\b/
message.reply(text: IDIOMS[:pretty])
when /\srepeat the past\b/
message.reply(text: IDIOMS[:repeat_past])
when /\sadvice\b/
message.reply(text: IDIOMS[:advice])
when /\sbook choice respond\b/
message.reply(text: IDIOMS[:book_choice_respond])
when "Thanks", "thanks", "thx", "thank you", "Thank you", "ty"
message.reply(text: IDIOMS[:thanks])
when /\wou are the best\b/
message.reply(text: IDIOMS[:the_best])
when /\slast words\b/
message.reply(text: IDIOMS[:last_words])
when "The Great Gatsby"
message.reply(text: IDIOMS[:gatsby])
when "Tender is the Night"
message.reply(text: IDIOMS[:tender])
when "This Side of Paradis..."
message.reply(text: IDIOMS[:paradise])
else
message.reply(text: IDIOMS[:ask_again])
end
end
end
IDIOMS = {
greeting: "Why hello. Thanks for checking in on old F Scott.",
fortune_cookie: "Never confuse a single defeat with a final defeat.",
exclamation: "Cut out all these exclamation points. An exclamation point is like laughing at your own joke.",
working_on: "Oh, all sorts of things. But let's not talk about plans. When you talk about plans, you take something away from them.",
look_like: "I am the finest, loveliest, tenderest, and most beautiful person I have ever known—and even that is an understatement.",
believe: "The test of a first-rate intelligence is the ability to hold two opposed ideas in the mind at the same time, and still retain the ability to function.",
why_write: "You don't write because you want to say something, you write because you have something to say.",
help_finding_job: "The idea that to make a man work you've got to hold gold in front of his eyes is a growth, not an axiom. We've done that for so long that we've forgotten there's any other way.",
writing_great_gatsby: "To write it, it took three months; to conceive it three minutes; to collect the data in it, all my life.",
not_up_to_standards: "I'm an intelligent dude, but obviously not up to your standards. Ask me something else.",
advice: "Drop it like F. Scott. That's the best I got :)",
thanks: "Why certainly. Anything else on your mind?",
pretty: "In his blue gardens men and girls came and went like moths among the whisperings and the champagne and the stars.",
repeat_past: "Why of course you can!",
real: "Action is character. So...yes.",
joke: "Ernest Hemingway",
the_best: "No kidding. Anything else you wanted to talk about?",
ask_again: "Alas, I don't quite understand your question. Ask me something else!",
last_words: "And so we beat on. Boats against the current. Borne back ceaselessly into the chats.",
gatsby: "Gatsby! What Gatsby? :) Jk, how can I help you today?",
tender: "There's no night more tender than the ones we spend together :) How can I help you today?",
paradise: "Good choice - may your life open up into an amazing burst of radiance :) How can I help you today?",
how_are_you: "Fine, lovely, tender--and I hope you are the same."
}
wait_for_user_input