funbox/smppex

delivery report generator

chemeris opened this issue · 3 comments

I think it make sense to add a generator for delivery reports into the library, because it's a common task and is not going to differ much from an app to an app. Something like this:

    def source_tuple(pdu) do
      Enum.map([:source_addr, :source_addr_ton, :source_addr_npi], fn x -> Pdu.field(pdu, x) end)
      |> List.to_tuple
    end

    def dest_tuple(pdu) do
      Enum.map([:destination_addr, :dest_addr_ton, :dest_addr_npi], fn x -> Pdu.field(pdu, x) end)
      |> List.to_tuple
    end

    @message_state_delivered 2
    def gen_delivery_report(pdu, resp_pdu, message \\ "", message_state \\ @message_state_delivered) do
      source = source_tuple(pdu)
      dest = dest_tuple(pdu)
      message_id = Pdu.field(resp_pdu, :message_id)
      SMPPEX.Pdu.Factory.delivery_report(message_id, source, dest, message, message_state)
    end

Not sure where to add this, though. So sending as an issue and not as a pull request.

I have attached a commit with required functionality, but slightly changed the interface.

Also, all SMSCs I have ever worked with were expected to swap source and dest addresses in delivery reports (since it is sent in the reverse direction as opposed to submit_sm)

Thank you!
Why do you require to pass message ID into the function instead of taking it from the submit_sm?

It seems you're correct about the dest/source swap, thanks.

Ok, disregard the question about the message ID.