lib/imperituroard/projects/mhub/subs/dabrab/dabrab_proced.rb in imperituroard-0.5.0 vs lib/imperituroard/projects/mhub/subs/dabrab/dabrab_proced.rb in imperituroard-0.5.1

- old
+ new

@@ -1,31 +1,30 @@ - - - class Dabrab -def num_formatter(infobip_msisdn, extra_id) - #[{"to"=>{"phoneNumber"=>"375297116638", "emailAddress"=>nil}}] - # [{"phone_number": 375298766719}, {"phone_number": 375295730878}] + def num_formatter(infobip_msisdn, extra_id) + #[{"to"=>{"phoneNumber"=>"375297116638", "emailAddress"=>nil}}] + # [{"phone_number": 375298766719}, {"phone_number": 375295730878}] - converted_msisdn_list = [] + converted_msisdn_list = [] - for g in infobip_msisdn - begin - converted_msisdn_list.append({"phone_number": g["to"]["phoneNumber"].to_i, "extra_id": extra_id}) - rescue - p "failed: #{g.to_s}" + for g in infobip_msisdn + begin + converted_msisdn_list.append({ + "phone_number": g["to"]["phoneNumber"].to_i + #"extra_id": extra_id + }) + rescue + p "failed: #{g.to_s}" + end + end + p converted_msisdn_list + converted_msisdn_list end - p converted_msisdn_list - converted_msisdn_list -end - - def send_responce_formatter(hub_answer) input = {:hub_answer => hub_answer} mess_to_recip = {} messages_sect = [] example = { @@ -43,46 +42,68 @@ } ] } p "send_responce_formatter(hub_answer)" - p hub_answer for a in hub_answer[:body][:res_body]["messages"] - s1 = {"to": {"phoneNumber": a["phone_number"]}, "status": {"groupId": 1, - "groupName": "PENDING", - "id": 26, - "name": "MESSAGE_ACCEPTED", - "description": "Message sent to next instance"}, - "messageId": a["message_id"]} + status1 = {} + if a["processed"] == true && a["accepted"] == true + status1 = {"to": {"phoneNumber": a["phone_number"]}, + "status": {"groupId": 1, + "groupName": "PENDING", + "id": 26, + "name": "MESSAGE_ACCEPTED", + "description": "Message sent to next instance"}, + "messageId": a["message_id"]} + else + status1 = {"to": {"phoneNumber": a["phone_number"]}, + "status": {"groupId": 5, + "groupName": "REJECTED", + "id": 21, + "name": "REJECTED_SYSTEM_ERROR", + "description": "Unknown error"}, + "messageId": a["message_id"]} + end - messages_sect.append(s1) + messages_sect.append(status1) end p messages_sect mess_to_recip = {"bulkId": "00000000-0000-0000-0000-000000000000", "messages": messages_sect} {:code => 200, :result => "Data processed", :body => {:mess_to_recip => mess_to_recip}} end - def delivery_report_transform(hub_report) #{"number"=>"375297116638", "time"=>1588673492000, "status"=>2, "substatus"=>23, "msg_status"=>23033, "message_id"=>"486649ba-a573-4ee9-8f58-018ed20ca6fd", "extra_id"=>"444/0/ServiceModel/ScGetReports.svc/GetReports", "sent_via"=>"viber", "controller"=>"reports", "action"=>"delivery", "report"=>{"number"=>"375297116638", "time"=>1588673492000, "status"=>2, "substatus"=>23, "msg_status"=>23033, "message_id"=>"486649ba-a573-4ee9-8f58-018ed20ca6fd", "extra_id"=>"444/0/ServiceModel/ScGetReports.svc/GetReports", "sent_via"=>"viber"}} - p hub_report p "hub_report" - data_for_status = { - 23011 => {:status_id => 5, :status_grid => 3, :status_grname => "DELIVERED", :status_name => "DELIVERED_TO_HANDSET", :status_descr => "Message delivered by SMS", - :error_id => 0, :error_grid => 0, :error_grname => "Ok", :error_name=> "NO_ERROR", :error_descr => "No Error", :error_permanent => false + :error_id => 0, :error_grid => 0, :error_grname => "Ok", :error_name => "NO_ERROR", :error_descr => "No Error", :error_permanent => false }, 23033 => {:status_id => 5, :status_grid => 3, :status_grname => "DELIVERED", :status_name => "DELIVERED_TO_HANDSET", :status_descr => "Message delivered by Viber", - :error_id => 0, :error_grid => 0, :error_grname => "Ok", :error_name=> "NO_ERROR", :error_descr => "No Error", :error_permanent => false - } + :error_id => 0, :error_grid => 0, :error_grname => "Ok", :error_name => "NO_ERROR", :error_descr => "No Error", :error_permanent => false + }, + 35015 => {:status_id => 15, :status_grid => 4, :status_grname => "EXPIRED", :status_name => "EXPIRED_EXPIRED", :status_descr => "SMS Message TTL EXPIRED", + :error_id => 6, :error_grid => 1, :error_grname => "HANDSET_ERRORS", :error_name => "EC_ABSENT_SUBSCRIBER_SM", :error_descr => "Subscriber is absent", :error_permanent => false + }, #message SMS expired + 36463 => {:status_id => 15, :status_grid => 4, :status_grname => "EXPIRED", :status_name => "EXPIRED_EXPIRED", :status_descr => "Viber Message TTL EXPIRED", + :error_id => 6, :error_grid => 1, :error_grname => "HANDSET_ERRORS", :error_name => "EC_ABSENT_SUBSCRIBER_SM", :error_descr => "Subscriber is absent.", :error_permanent => false + }, #message Viber expired + 36010 => {:status_id => 4, :status_grid => 2, :status_grname => "UNDELIVERABLE", :status_name => "UNDELIVERABLE_REJECTED_OPERATOR", :status_descr => "SMS. Subscriber not exists", + :error_id => 6, :error_grid => 1, :error_grname => "HANDSET_ERRORS", :error_name => "EC_UNKNOWN_SUBSCRIBER", :error_descr => "Subscriber not found.", :error_permanent => true + }, #SMS subscriber not exists + 36131 => {:status_id => 4, :status_grid => 2, :status_grname => "UNDELIVERABLE", :status_name => "UNDELIVERABLE_REJECTED_OPERATOR", :status_descr => "SMS. Unknown subscriber", + :error_id => 6, :error_grid => 1, :error_grname => "HANDSET_ERRORS", :error_name => "EC_UNKNOWN_SUBSCRIBER", :error_descr => "Subscriber not found.", :error_permanent => true + }, #SMS unknown subscriber + 36505 => {:status_id => 4, :status_grid => 2, :status_grname => "UNDELIVERABLE", :status_name => "UNDELIVERABLE_REJECTED_OPERATOR", :status_descr => "Viber. Subscriber not exists", + :error_id => 6, :error_grid => 1, :error_grname => "HANDSET_ERRORS", :error_name => "EC_UNKNOWN_SUBSCRIBER", :error_descr => "Subscriber not found.", :error_permanent => true + } #Viber subscriber not exists } if data_for_status[hub_report[:msg_status]] != nil && data_for_status[hub_report[:msg_status]] != {} && data_for_status[hub_report[:msg_status]] != [] && data_for_status[hub_report[:msg_status]] != "" report_to_recip = { "results": [ @@ -140,13 +161,9 @@ } } ] } end - - - - {:code => 200, :result => "Data processed", :body => {:report_to_recip => report_to_recip}} end end