-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
44 lines (40 loc) · 1018 Bytes
/
app.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
require 'sinatra'
require 'gmail'
require 'twilio-ruby'
configure :development do
require 'sinatra/reloader'
end
Twilio.configure do |config|
config.account_sid = ENV['ACCOUNT_SID']
config.auth_token = ENV['AUTH_TOKEN']
end
get '/receive' do
@client = Twilio::REST::Client.new
message = params[:Body].split(' ')
if message.length == 3
username = message[0]
password = message[1]
command = message[2]
gmail = Gmail.new(username, password)
if command.eql? 'count'
@client.messages.create(
from: ENV['MY_NUMBER'],
to: params[:From],
body: gmail.inbox.count(:unread)
)
elsif command.eql? 'latest'
gmail.peek = true
@client.messages.create(
from: ENV['MY_NUMBER'],
to: params[:From],
body: gmail.inbox.emails(:unread, :after => Date.today.prev_day)[0].message
)
end
else
@client.messages.create(
from: '+19284332264',
to: params[:From],
body: 'Invalid request'
)
end
end