badlee / kannel.js

Javascript implementation of Kannel Box protocol
http://badlee.github.io/kannel.js/
41 stars 11 forks source link

is coding and charset MSG properties used? #1

Open tamerMarzouk opened 7 years ago

tamerMarzouk commented 7 years ago

When using the smsbox.send, I don't see that the charset nor coding properties are used. How do I send Arabic text. In kannel url I used to set coding=2 url parameter, and charset=UTF-16BE, and text = hex I changed the sendSMS function like this to add charset and coding the text I sent as a buffer with hex encoding.


smsbox.prototype.sendSMS = function(conf) {
    var def = {
        id: true,
        time: Math.floor((new Date).getTime() / 1000),
        sender: undefined,
        receiver: undefined,
        msgdata: undefined,
        charset: undefined, //added these two lines
        coding: undefined
    };
    for (var property in def)
        if (!conf.hasOwnProperty(property))
            conf[property] = def[property];
    if (!conf.receiver || !conf.msgdata) return null;
    this.write("sms", {
        sender: conf.sender,
        receiver: conf.receiver,
        msgdata: conf.msg || conf.text || conf.msgdata,
        time: conf.time,
        id: conf.id || true,
        sms_type: status.sms.mt_reply,
        coding: conf.coding, //added these two lines
        charset: conf.charset
    });
    return true;
};
badlee commented 7 years ago

Hey @tamerMarzouk thank's to use my nodejs module, I'll add this feature.

badlee commented 7 years ago

@tamerMarzouk, I have add two functions to hep you,

app.sendUCS2SMS({
    sender: 'TEST',
    receiver: '06462845',
    msgdata: 'Bonjour, Hi, 你好, صباح الخير', // UCS2 text
});
app.flashUCS2SMS({
    sender: 'TEST',
    receiver: '06462845',
    msgdata: 'Bonjour, Hi, 你好, صباح الخير', // UCS2 text
});

I hope help you again.

tamerMarzouk commented 7 years ago

I think the example is not correct. you should provide the msgdata must be encoded as UTF-16BE, if sent as is it will not received correctly. I use

msgdata: Buffer.from('063106330627064406290020','hex')

badlee commented 7 years ago

Can you test, UCS2 is UTF16BE, the buffer has correctly converted now.

tamerMarzouk commented 7 years ago

My Setup is not connected to a live SMSC right now. I will try to send as soon as I could. But in nodejs , UCS2 s an alias for UTF-16LE

badlee commented 7 years ago

@tamerMarzouk, do you have test the new version of kannel(nom module)?

tamerMarzouk commented 7 years ago

I've tested the new version of kannel. The MSG class has a missing ")" on line node_modules/kannel/lib/MSG.js:76 I've added the missing ")" and tried using the flashUCS2SMS with utf-16be encoded buffer but the SMS received was not correct format. I tried using flashUCS2SMS with an Arabic string as is but the msg received was not correct format and the coding was 0 and charset utf-8

tamerMarzouk commented 7 years ago

I've just used sendSMS function and added two lines to the following code

 this.write("sms", {
        sender: conf.sender,
        receiver: conf.receiver,
        msgdata: conf.msg || conf.text || conf.msgdata,
        coding: conf.coding, //added this line
        charset: conf.charset,// added this line
        time: conf.time,
        id: conf.id || true,
        sms_type: status.sms.mt_reply
    });

then When I send Arabic text I provide code=2 and charset='UTF-16BE' and the msgdata is a string representation in hex for example '06310633062706440629' which is the Arabic word 'رسالة'

The above works good for me and is the same format received by an SMS app as if it was sent from kannel push SMS URL.

badlee commented 7 years ago

Hi @tamerMarzouk,

Please update kannel.js to the last version, and use sendUCS2SMS or flashUCS2SMS.