$LOAD_PATH.unshift File.expand_path("../projects/mhub", __dir__) $LOAD_PATH.unshift File.expand_path("../projects/mhub/subs/dabrab", __dir__) require 'imperituroard/projects/mhub/infobip' require 'imperituroard/projects/mhub/sk' require 'imperituroard/projects/mhub/subs/dabrab/dabrab_proced' require 'imperituroard/projects/mhub/subs/dabrab/dabrab_platform' require 'json' require 'ipaddr' require 'date' require 'net/http' require 'uri' class MhubFunctions_2 attr_accessor :sk_url, :sk_login, :sk_password, :mhub_connector, :internal_func, :dabrab_connecter, :static_callback, :crm_connector, :telegram_connector, :sms_alphaname, :log_level def initialize(sk_url_simple, sk_login, sk_password, telegram_api_url, telegram_chat_id, sk_url_broadcast, static_callback, crm_callback_url, crm_login, crm_password, sms_alphaname, log_level) @sk_url = sk_url_simple @sk_login = sk_login @sk_password = sk_password @log_level = log_level @internal_func = InternalFunc.new @mhub_connector = Sksk_2.new(sk_url_simple, sk_login, sk_password, sk_url_broadcast, telegram_api_url, telegram_chat_id, log_level) @internal_func = InternalFunc.new @dabrab_connecter = Dabrab.new @telegram_connector = Telegram_2.new(telegram_api_url, telegram_chat_id) @static_callback = static_callback @crm_connector = Crm_2.new(crm_callback_url, crm_login, crm_password, telegram_api_url, telegram_chat_id, log_level) @sms_alphaname = sms_alphaname end #{"destinations"=>[{"to"=>{"phoneNumber"=>"375297116638", "emailAddress"=>nil}}], # "scenarioKey"=>"1", "viber"=>nil, "sms"=>{"text"=>"карточка готова"}, # "sendAt"=>"2019-08-15T08:40:00.000", "notifyUrl"=>"https://bpmonline.bankdabrabyt.by:444/0/ServiceModel/ScGetReports.svc/GetReports", # "notifyContentType"=>"application/json", "controller"=>"bank", "action"=>"api", # "bank"=>{"destinations"=>[{"to"=>{"phoneNumber"=>"375297116638", "emailAddress"=>nil}}], "scenarioKey"=>"1", # "viber"=>nil, "sms"=>{"text"=>"карточка готова"}, "sendAt"=>"2019-08-15T08:40:00.000", # "notifyUrl"=>"https://bpmonline.bankdabrabyt.by:444/0/ServiceModel/ScGetReports.svc/GetReports", # "notifyContentType"=>"application/json"}} #for bank dabrabyt def get_send_message_2(params, ip_src, ip_real, ip_vip) input_params = {:params => params} output_params = {} hub_resp = {} null_statement = [nil, "nil", "", "null"] mes_data = {} begin # if params["destinations"].length == 1 # msisdn = params["destinations"][0]["to"]["phoneNumber"] # if null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) # hub_resp = mhub_connector.sk_send_sms_one(msisdn, params["notifyUrl"], params["sms"]["text"], "TEST") # elsif !null_statement.include?(params["viber"]) && null_statement.include?(params["sms"]) # hub_resp = mhub_connector.sk_send_viber_one(msisdn, params["notifyUrl"], params["viber"]["text"]) # elsif !null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) # hub_resp = mhub_connector.sk_send_viber_sms_one(msisdn, params["notifyUrl"], params["sms"]["text"], params["viber"]["text"], "TEST") # else # output_params = {"code": 501, "result": "Invalid input data st1", "answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}} # end # elsif params["destinations"].length > 1 # # msisdn2 = dabrab_connecter.num_formatter(params["destinations"], params["notifyUrl"].split(":")[2]) # # if null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) # hub_resp = mhub_connector.sk_send_sms_list(msisdn2, params["notifyUrl"], params["sms"]["text"], "TEST") # elsif !null_statement.include?(params["viber"]) && null_statement.include?(params["sms"]) # hub_resp = mhub_connector.sk_send_viber_list(msisdn2, params["notifyUrl"], params["viber"]["text"]) # elsif !null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) # hub_resp = mhub_connector.sk_send_viber_sms_list(msisdn2, params["notifyUrl"], params["sms"]["text"], params["viber"]["text"], "TEST") # else # output_params = {"code": 502, "result": "Invalid input data st2", "answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}} # end # else # output_params = {"code": 503, "result": "Invalid recipients", "answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}} # end if params["destinations"].length >= 1 msisdn2 = dabrab_connecter.num_formatter(params["destinations"], params["notifyUrl"].split(":")[2]) if null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) hub_resp = mhub_connector.sk_send_sms_list(msisdn2, static_callback, params["sms"]["text"], sms_alphaname) elsif !null_statement.include?(params["viber"]) && null_statement.include?(params["sms"]) hub_resp = mhub_connector.sk_send_viber_list(msisdn2, static_callback, params["viber"]["text"]) elsif !null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) p "vibersms" p msisdn2 hub_resp = mhub_connector.sk_send_viber_sms_list(msisdn2, static_callback, params["sms"]["text"], params["viber"]["text"], sms_alphaname) else output_params = {"code": 502, "result": "Invalid input data st2", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} end mes_data = dabrab_connecter.send_responce_formatter(hub_resp) else output_params = {"code": 503, "result": "Invalid recipients", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} end output_params = {"code": 200, "result": "Data processed", "body": {"answer": mes_data[:body][:mess_to_recip], "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} rescue output_params = {"code": 500, "result": "MhubFunctions_2.get_send_message_2: Unknown SDK error", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} telegram_connector.telegram_message(output_params) end internal_func.printer_texter({:input => input_params, :output => output_params, :hub_resp => hub_resp, :procedure => "Mhub_2.get_send_message"}, log_level) output_params end #for bank dabrabyt for massive nums def get_send_message_mass_2(params, ip_src, ip_real, ip_vip, slice_number, time_pause_minutes) input_params = {:params => params} output_params = {} null_statement = [nil, "nil", "", "null"] mes_data_answ = [] begin internal_func.printer_texter({:input => params, :procedure => "Mhub_2.get_send_message_mass_2"}, log_level) if params["destinations"].length >= 1 msisdn2 = dabrab_connecter.num_formatter(params["destinations"], params["notifyUrl"].split(":")[2]) splitted_parts = msisdn2.each_slice(slice_number).to_a for part_list in splitted_parts internal_func.printer_texter({:input => part_list, :procedure => "Mhub_2.get_send_message_mass_2"}, log_level) hub_resp = {} if null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) hub_resp = mhub_connector.sk_send_sms_list(part_list, static_callback, params["sms"]["text"], sms_alphaname, time_pause_minutes) elsif !null_statement.include?(params["viber"]) && null_statement.include?(params["sms"]) hub_resp = mhub_connector.sk_send_viber_list(part_list, static_callback, params["viber"]["text"], time_pause_minutes) elsif !null_statement.include?(params["viber"]) && !null_statement.include?(params["sms"]) hub_resp = mhub_connector.sk_send_viber_sms_list(part_list, static_callback, params["sms"]["text"], params["viber"]["text"], sms_alphaname, time_pause_minutes) else output_params = {"code": 502, "result": "Invalid input data st2", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} end mes_data = dabrab_connecter.send_responce_formatter(hub_resp) internal_func.printer_texter({:input => mes_data, :procedure => "Mhub_2.get_send_message_mass_2"}, log_level) mes_data_answ = mes_data_answ + mes_data[:body][:mess_to_recip][:messages] end else output_params = {"code": 503, "result": "Invalid recipients", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} end output_params = {"code": 200, "result": "Data processed", "body": {"answer": {"bulkId": "00000000-0000-0000-0000-000000000000", "messages": mes_data_answ}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} rescue output_params = {"code": 500, "result": "MhubFunctions_2.get_send_message_2: Unknown SDK error", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} telegram_connector.telegram_message(output_params) end internal_func.printer_texter({:input => input_params, :output => output_params, :hub_resp => {}, :procedure => "Mhub_2.get_send_message"}, log_level) output_params end #for bank dabrabyt def rec_deliv_report_2(params, ip_src, ip_real, ip_vip) input_params = {:params => params, :ip_src => ip_src, :ip_real => ip_real, :ip_vip => ip_vip} output_params = {} hub_resp = {} begin mes_report = dabrab_connecter.delivery_report_transform(params)[:body][:report_to_recip] result = crm_connector.crm_status_2(mes_report) if result[:body][:res_body]["GetReportsResult"]=="" output_params = {"code": 200, "result": "Data processed", "body": {"answer": {"code": 200, "status": "Success"}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} else output_params = {"code": 202, "result": "CRM returned error #{result[:body][:res_body]["GetReportsResult"].to_s}", "body": {"answer": {"code": 200, "status": "Success"}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} end rescue output_params = {"code": 500, "result": "MhubFunctions_2.rec_deliv_report_2: Unknown SDK error", "body": {"answer": {}, "sender": {"ip_src": ip_src, "ip_real": ip_real, "ip_vip": ip_vip}}} telegram_connector.telegram_message(output_params) end internal_func.printer_texter({:input => input_params, :output => output_params, :hub_resp => hub_resp, :procedure => "Mhub_2.recieve_delivery_report"}, log_level) output_params end end