Skip to content

Commit

Permalink
interpolated response (huginn#1682)
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagotalma authored and cantino committed Sep 15, 2016
1 parent 5868c7b commit 4fdd69c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 1 addition & 5 deletions app/models/agents/webhook_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def receive_web_request(params, method, format)
create_event(payload: payload)
end

[response_message, code]
[interpolated(params)['response'] || 'Event Created', code]
end

def working?
Expand All @@ -108,9 +108,5 @@ def validate_options
def payload_for(params)
Utils.value_at(params, interpolated['payload_path']) || {}
end

def response_message
interpolated['response'] || 'Event Created'
end
end
end
6 changes: 6 additions & 0 deletions spec/models/agents/webhook_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
expect(out).to eq(['', 201])
end

it 'should respond with interpolated response message if configured with `response` option' do
agent.options['response'] = '{{some_key.people[1].name}}'
out = agent.receive_web_request({ 'secret' => 'foobar', 'some_key' => payload }, "post", "text/html")
expect(out).to eq(['jon', 201])
end

it 'should respond with `Event Created` if the response option is nil or missing' do
agent.options['response'] = nil
out = agent.receive_web_request({ 'secret' => 'foobar', 'some_key' => payload }, "post", "text/html")
Expand Down

0 comments on commit 4fdd69c

Please sign in to comment.