-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
36 lines (30 loc) · 878 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
require 'json'
require 'sinatra'
require 'sinatra/activerecord'
require './config/database'
Dir['./app/models/*.rb'].each { |file| require file }
Dir['./app/services/**/*.rb'].each { |file| require file }
class App < Sinatra::Base
get '/' do
'Your translator bot for English -> Brazilian Portuguese'
end
post '/webhook' do
request.body.rewind
result = JSON.parse(request.body.read)['queryResult']
if result['contexts'].present?
response = InterpretService.call(result['action'],
result['contexts'][0]['parameters'])
else
response = InterpretService.call(result['action'], result['parameters'])
end
content_type :json, charset: 'utf-8'
{
"payload": {
"telegram": {
"text": response,
"parse_mode": "Markdown"
}
}
}.to_json
end
end