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:
2022-01-18 19:15:24 +03:00
parent 99f9328afd
commit 30b60899d5
4 changed files with 48 additions and 4 deletions

View File

@@ -77,8 +77,11 @@ bot.on("msg:contact", async (ctx) => {
log.debug(ctx.update, "msg:contact received");
const contact = ctx.msg.contact;
if (ctx.from.id === contact.user_id) {
await cache.set(contact.user_id, contact.phone_number.slice(1));
if (
ctx.from.id === contact.user_id &&
util.isKenyanNumber(contact.phone_number)
) {
await cache.set(contact.user_id, contact.phone_number);
return ctx.reply(
"Phone number successfully linked. /start the bot again to access your Sarafu account."

View File

@@ -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 = {
createKeyboard,
parseUssdResponse,
isKenyanNumber,
};