-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
35 lines (29 loc) · 943 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
require 'json'
require 'sinatra'
Dir["./app/services/**/*.rb"].each {|f| require f}
Dir["./app/errors/**/*.rb"].each {|f| require f}
class App < Sinatra::Base
post '/webhook' do
request.body.rewind
result = JSON.parse(request.body.read)["queryResult"]
begin
if result.has_value?("contexts")
response = InterpretService.call(result["action"], result["context"][0]["parameters"])
else
response = InterpretService.call(result["action"], result["parameters"])
end
rescue Errors::ResponseError => e
response = e.message
end
content_type :json, charset: 'utf-8'
{
"fulfillmentText": response,
"payload":{
"telegram": {
"text": response,
"parse_mode": "Markdown"
}
}
}.to_json
end
end