tg fix: (release v0.3.0) phone number formats
* on tg desktop phones are prepended with a "+" * on tg phone, no "+"
This commit is contained in:
parent
99f9328afd
commit
30b60899d5
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ussd-tg-proxy",
|
"name": "ussd-tg-proxy",
|
||||||
"version": "0.2.6",
|
"version": "0.3.0",
|
||||||
"description": "ussd-tg-proxy",
|
"description": "ussd-tg-proxy",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"repository": "https://git.grassecon.net/grassrootseconomics/ussd-tg-proxy.git",
|
"repository": "https://git.grassecon.net/grassrootseconomics/ussd-tg-proxy.git",
|
||||||
|
@ -77,8 +77,11 @@ bot.on("msg:contact", async (ctx) => {
|
|||||||
log.debug(ctx.update, "msg:contact received");
|
log.debug(ctx.update, "msg:contact received");
|
||||||
const contact = ctx.msg.contact;
|
const contact = ctx.msg.contact;
|
||||||
|
|
||||||
if (ctx.from.id === contact.user_id) {
|
if (
|
||||||
await cache.set(contact.user_id, contact.phone_number.slice(1));
|
ctx.from.id === contact.user_id &&
|
||||||
|
util.isKenyanNumber(contact.phone_number)
|
||||||
|
) {
|
||||||
|
await cache.set(contact.user_id, contact.phone_number);
|
||||||
|
|
||||||
return ctx.reply(
|
return ctx.reply(
|
||||||
"Phone number successfully linked. /start the bot again to access your Sarafu account."
|
"Phone number successfully linked. /start the bot again to access your Sarafu account."
|
||||||
|
13
src/util.js
13
src/util.js
@ -15,7 +15,20 @@ function parseUssdResponse(input) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isKenyanNumber(input) {
|
||||||
|
if (input.substr(0, 1) === "+") {
|
||||||
|
input = input.split("+")[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.substr(0, 3) === "254") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
createKeyboard,
|
createKeyboard,
|
||||||
parseUssdResponse,
|
parseUssdResponse,
|
||||||
|
isKenyanNumber,
|
||||||
};
|
};
|
||||||
|
@ -3,7 +3,7 @@ const test = require("tap").test;
|
|||||||
const util = require("../src/util");
|
const util = require("../src/util");
|
||||||
|
|
||||||
test("util", (t) => {
|
test("util", (t) => {
|
||||||
t.plan(4);
|
t.plan(8);
|
||||||
|
|
||||||
t.test("keyboard from single digit reply options", (t) => {
|
t.test("keyboard from single digit reply options", (t) => {
|
||||||
const rawText = `CON Balance 80.0 GFT
|
const rawText = `CON Balance 80.0 GFT
|
||||||
@ -66,4 +66,32 @@ test("util", (t) => {
|
|||||||
t.same(output, expect);
|
t.same(output, expect);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
t.test("kenyan number formatted", (t) => {
|
||||||
|
const number = "+254700123456";
|
||||||
|
|
||||||
|
t.equal(util.isKenyanNumber(number), true);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test("kenyan number unformatted", (t) => {
|
||||||
|
const number = "254700123456";
|
||||||
|
|
||||||
|
t.equal(util.isKenyanNumber(number), true);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test("non kenyan number formatted", (t) => {
|
||||||
|
const number = "+441632960198";
|
||||||
|
|
||||||
|
t.equal(util.isKenyanNumber(number), false);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test("non kenyan number unformatted", (t) => {
|
||||||
|
const number = "12029182132";
|
||||||
|
|
||||||
|
t.equal(util.isKenyanNumber(number), false);
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user