@@ -785,34 +785,36 @@ class WebhookHandler < Goliath::API
puts 'ENV: ' + env.reject{ |k| k == 'params' }.to_s
+ jparams = params
+
users_num = ''
others_num = ''
- if params['direction'] == 'in'
- users_num = params['to']
- others_num = params['from']
- elsif params['direction'] == 'out'
- users_num = params['from']
- others_num = params['to']
+ if jparams['direction'] == 'in'
+ users_num = jparams['to']
+ others_num = jparams['from']
+ elsif jparams['direction'] == 'out'
+ users_num = jparams['from']
+ others_num = jparams['to']
else
# TODO: exception or similar
- puts "big problem: '" + params['direction'] + "'" + body
+ puts "big prob: '" + jparams['direction'] + "'" + body
return [200, {}, "OK"]
end
- puts 'BODY - messageId: ' + params['messageId'] +
- ', eventType: ' + params['eventType'] +
- ', time: ' + params['time'] +
- ', direction: ' + params['direction'] +
- ', state: ' + params['state'] +
- ', deliveryState: ' + (params['deliveryState'] ?
- params['deliveryState'] : 'NONE') +
- ', deliveryCode: ' + (params['deliveryCode'] ?
- params['deliveryCode'] : 'NONE') +
- ', deliveryDesc: ' + (params['deliveryDescription'] ?
- params['deliveryDescription'] : 'NONE') +
- ', tag: ' + (params['tag'] ? params['tag'] : 'NONE') +
- ', media: ' + (params['media'] ? params['media'].to_s :
- 'NONE')
+ puts 'BODY - messageId: ' + jparams['messageId'] +
+ ', eventType: ' + jparams['eventType'] +
+ ', time: ' + jparams['time'] +
+ ', direction: ' + jparams['direction'] +
+ ', state: ' + jparams['state'] +
+ ', deliveryState: ' + (jparams['deliveryState'] ?
+ jparams['deliveryState'] : 'NONE') +
+ ', deliveryCode: ' + (jparams['deliveryCode'] ?
+ jparams['deliveryCode'] : 'NONE') +
+ ', deliveryDesc: ' + (jparams['deliveryDescription'] ?
+ jparams['deliveryDescription'] : 'NONE') +
+ ', tag: ' + (jparams['tag'] ? jparams['tag'] : 'NONE') +
+ ', media: ' + (jparams['media'] ?
+ jparams['media'].to_s : 'NONE')
if others_num[0] != '+'
# TODO: check that others_num actually a shortcode first
@@ -834,15 +836,15 @@ class WebhookHandler < Goliath::API
end
msg = ''
- case params['direction']
+ case jparams['direction']
when 'in'
text = ''
- case params['eventType']
+ case jparams['eventType']
when 'sms'
- text = params['text']
+ text = jparams['text']
when 'mms'
has_media = false
- params['media'].each do |media_url|
+ jparams['media'].each do |media_url|
if not media_url.end_with?(
'.smil', '.txt', '.xml'
)
@@ -856,7 +858,7 @@ class WebhookHandler < Goliath::API
end
end
- if params['text'].empty?
+ if jparams['text'].empty?
if not has_media
text = '[suspected group msg '\
'with no text (odd)]'
@@ -864,13 +866,13 @@ class WebhookHandler < Goliath::API
else
text = if has_media
# TODO: write/use a caption XEP
- params['text']
+ jparams['text']
else
'[suspected group msg '\
'(recipient list not '\
'available) with '\
'following text] ' +
- params['text']
+ jparams['text']
end
end
@@ -884,20 +886,20 @@ class WebhookHandler < Goliath::API
return [200, {}, "OK"]
else
- text = "unknown type (#{params['eventType']})"\
- " with text: " + params['text']
+ text = "unknown type (#{jparams['eventType']})"\
+ " with text: " + jparams['text']
# TODO: log/notify of this properly
puts text
end
msg = Blather::Stanza::Message.new(bare_jid, text)
- else # per prior switch, this is: params['direction'] == 'out'
- tag_parts = params['tag'].split(/ /, 2)
+ else # per prior switch, this is: jparams['direction'] == 'out'
+ tag_parts = jparams['tag'].split(/ /, 2)
id = WEBrick::HTTPUtils.unescape(tag_parts[0])
resourcepart = WEBrick::HTTPUtils.unescape(tag_parts[1])
- case params['deliveryState']
+ case jparams['deliveryState']
when 'not-delivered'
# create a bare message like the one user sent
msg = Blather::Stanza::Message.new(
@@ -932,7 +934,7 @@ class WebhookHandler < Goliath::API
else
# TODO: notify somehow of unknown state receivd?
puts "message with id #{id} has "\
- "other state #{params['deliveryState']}"
+ "othr state #{jparams['deliveryState']}"
return [200, {}, "OK"]
end