Issue #3 resolved
Anonymous created an issue

I was wondering if you could help me? I would like to add a new gateway pull request, but I'm trying to create the correct regular expression that parses the response for success and error format when setting up a gateway for django-sms-gateway.

django-sms-gateway asks for... A regular expression that parses the response. May contain named groups for "gateway_message_id", "status_message" and "status_code".

This is what I have tried for the following gateway that's shown below but it does not match...

(?P<status_code>[0-9]+)\|(?P<status_message>.+)\|(?P<gateway_message_id>[a-zA-Z0-9-]+)

the gateway returns this following text including the headers...

error code|error text|submission reference
0|sms submitted|eb725f96b4b094d5f8318741cc1a545f-2 

and successful...

error code|error text|submission reference
0|sms submitted|[32 characters]-[1 character] 

in the db status_text all i get matched is the word 'error text'.

this is the gateway I'm trying to integrate (see page 5) http://www.itagg.com/downloads/techdocs/itagg_api_std.pdf

any help would really, really be appreciated.

Comments (7)

  1. Matthew Schinckel repo owner

    I'll have a bit of a look at some stage when I get some free time.

    Can you attach a dumpdata of what your gateway setup looks like (without username/password), so I can use that?

    Cheers.

  2. Anonymous

    ref: http://www.itagg.com/downloads/techdocs/itagg_api_std.pdf

    {
            "pk": null,
            "model": "sms.gateway",
            "fields": {
                "content_keyword": "txt",
                "success_format": "(?P<status_code>[0-9]+)|(?P<status_message>.+)|(?P<gateway_message_id>[a-zA-Z0-9-]+)",
                "error_format": "(?P<status_code>[0-9]+)|(?P<status_message>.+)|(?P<gateway_message_id>[a-zA-Z0-9-]+)",
                "name": "iTagg",
                "status_status": "status",
                "settings": {
                    "pwd": "_PASWORD_",
                    "from": "_FROM_",
                    "usr": "-USER_"
                },
                "status_date": "timestamp",
                "reply_sender": "",
                "base_url": "https://secure.itagg.com/smsg/sms.mes",
                "status_error_code": "status",
                "reply_date": "",
                "recipient_keyword": "to",
                "status_msg_id": "apiMsgId",
                "reply_date_format": "%Y-%m-%d %H:%M:%S",
                "status_mapping": {
                    "201": "Failed",
                    "202": "Failed",
                    "301": "Failed",
                    "1": "Failed",
                    "0": "Sent",
                    "3": "Failed",
                    "2": "Failed",
                    "102": "Failed",
                    "100": "Failed",
                    "101": "Failed"
                },
                "uuid_keyword": "climsgid",
                "reply_content": "",
                "status_date_format": ""
            }
        }
    
  3. Anonymous

    The only way I can get it to work is to split the line in models gateway.py on line 161 status_msg = '\n'.join(res.readlines()[1:])

    then use the regex

    (?P<status_code>^[0-9][^|]*)\|(?P<status_message>[^|]+)\|(?P<gateway_message_id>.+)

    but this is a bit of a hack

  4. Matthew Schinckel repo owner

    Yep, it looks like the provider is returning two lines.

    Your regular expression should be able to just ignore the first line.

    (.*\n)(?P<status_code>[0-9]+)\|(?P<status_message>[^|]+)\|(?P<gateway_message_id>.+)
    

    That should work. Preliminary testing suggests it does.

    >>> re.match('(.*\n)(?P<status_code>[0-9]+)\|(?P<status_message>[^|]+)\|(?P<gateway_message_id>.+)', data).groupdict()
    {'status_code': '0', 'status_message': 'sms submitted', 'gateway_message_id': 'eb725f96b4b094d5f8318741cc1a545f-2'}
    
  5. Log in to comment