lib/imperituroard/projects/mhub/subs/dabrab/dabrab_proced.rb in imperituroard-0.5.7 vs lib/imperituroard/projects/mhub/subs/dabrab/dabrab_proced.rb in imperituroard-0.5.8

- old
+ new

@@ -1,7 +1,119 @@ class Dabrab + def dabrabyt_text_field_parse(stri) + button_url = "" + image = "" + button_text = "" + text = stri + + ############# + #0 - Text only + #1 - Text + Button + #2 - Text + Image + Button + #3 - image only + ############# + scheme = 0 + scheme_dic = {0 => "Text only", 1 => "Text+Button", 2 => "Text+Image+Button", 3 => "Image only"} + ############# + + output_answer = {} + sk_format = {} + + begin + + regexp_image1 = /(image:(\S+)[\s\n]?)/ + button_url1 = /(button_url:(\S+)[\s\n]?)/ + button_text1 = /(button_text:["']([^"]+)["'][\s\n])/ + + button_url_dat = stri.scan(button_url1) + button_text_dat = stri.scan(button_text1) + image_dat = stri.scan(regexp_image1) + + + p button_url_dat + p button_text_dat + p image_dat + + begin + if button_url_dat != [] && button_url_dat != nil && button_url_dat != "" + button_url = button_url_dat[0][1] + text = text.gsub(button_url_dat[0][0], "") + end + rescue + nil + end + + begin + if button_text_dat != [] && button_text_dat != nil && button_text_dat != "" + button_text = button_text_dat[0][1] + text = text.gsub(button_text_dat[0][0], "") + end + rescue + nil + end + + begin + if image_dat != [] && image_dat != nil && image_dat != "" + image = image_dat[0][1] + text = text.gsub(image_dat[0][0], "") + end + rescue + nil + end + text = text.gsub(/\s+$/, '').gsub(/\n$/, '') + + + if button_url != "" && button_text != "" && image != "" #111 + scheme = 2 + elsif button_url != "" && button_text != "" && image == "" #110 + scheme = 1 + elsif button_url == "" && button_text == "" && image != "" #001 + if text == "" + scheme = 3 + else + scheme = 2 + button_url = image + button_text = "Открыть" + end + elsif button_url != "" && button_text == "" && image != "" #101 + scheme = 2 + button_text = "Открыть" + elsif button_url == "" && button_text != "" && image != "" #011 + scheme = 2 + button_url = image + elsif button_url == "" && button_text != "" && image == "" #010 + scheme = 0 + elsif button_url != "" && button_text == "" && image == "" #100 + button_text = "Открыть" + scheme = 1 + else + scheme = 0 + end + + if scheme==0 + sk_format = {"text": text, "ttl": 60} + elsif scheme==1 + sk_format = {"text": text, "ttl": 60, "caption": button_text, "action": button_url} + elsif scheme==2 + sk_format = {"text": text, "ttl": 60, "caption": button_text, "action": button_url, "img": image} + elsif scheme==3 + sk_format = {"img": image, "ttl": 60} + else + nil + end + + p sk_format + + output_answer ={:code => 200, :result => "Success", :body => {:to_sk_format => sk_format, :button_url => button_url, :image => image, :button_text => button_text, :text => text, :scheme => scheme, :scheme_dic => scheme_dic[scheme]}} + rescue + output_answer ={:code => 507, :result => "dabrabyt_text_field_parse: Unknown error"} + end + output_answer + end + + def num_formatter(infobip_msisdn, extra_id) #[{"to"=>{"phoneNumber"=>"375297116638", "emailAddress"=>nil}}] # [{"phone_number": 375298766719}, {"phone_number": 375295730878}] converted_msisdn_list = [] @@ -48,23 +160,23 @@ for a in hub_answer[:body][:res_body]["messages"] 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"]} + "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"]} + "status": {"groupId": 5, + "groupName": "REJECTED", + "id": 21, + "name": "REJECTED_SYSTEM_ERROR", + "description": "Unknown error"}, + "messageId": a["message_id"]} end messages_sect.append(status1) end