11 Commits

Author SHA1 Message Date
0e1fbfeb1b release: v0.2.5 2022-01-18 15:57:00 +03:00
4530c7105d fix: tg contact behaviour
* sometimes  atg update does not include a plus symbol
2022-01-18 15:51:11 +03:00
aace2e98e1 release: v0.2.4 2022-01-18 14:57:24 +03:00
f61500f3e6 fix: add timeout to request
* incase the ussd-server is down or unresponsive, return a message to tg
2022-01-18 14:50:20 +03:00
05e441f6a1 release: v0.2.3 2022-01-17 18:35:09 +03:00
368f297c6b fix: escape dot char in regex 2022-01-17 18:34:54 +03:00
5257967f88 release: v0.2.2 2022-01-17 18:14:08 +03:00
1e438ae73e fix: redundant contact check 2022-01-17 18:13:52 +03:00
c51fc24478 release v0.2.1 2022-01-17 17:06:39 +03:00
e3b11fb719 add: dockerfile
* change polling behaviour to be dev only
2022-01-17 17:06:29 +03:00
441ca421ee tests: (fix) remove endAll on util 2022-01-17 15:38:24 +03:00
12 changed files with 14697 additions and 2450 deletions

2
.dockerignore Normal file
View File

@@ -0,0 +1,2 @@
.nyc*
node_modules

12
Dockerfile Normal file
View File

@@ -0,0 +1,12 @@
FROM node:17-alpine
ENV NODE_ENV production
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 80
CMD [ "node", "src/" ]

View File

@@ -1,4 +1,4 @@
[server]
host=0.0.0.0
port=3030
port=80
endpoint=

View File

@@ -1,3 +1,2 @@
[telegram]
polling=true
token=

12058
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "ussd-tg-proxy",
"version": "0.0.2",
"version": "0.2.5",
"description": "ussd-tg-proxy",
"main": "src/index.js",
"repository": "https://git.grassecon.net/grassrootseconomics/ussd-tg-proxy.git",

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.msg.reply_to_message.from.is_bot && ctx.from.id === contact.user_id) {
if (contact.phone_number.slice(0, 4) !== "+254") {
if (ctx.from.id === contact.user_id) {
if (
contact.phone_number.slice(0, 4) !== "+254" ||
contact.phone_number.slice(0, 3) !== "254"
) {
return ctx.reply("Sarafu is only available in Kenya at the moment.");
}
@@ -89,7 +92,6 @@ bot.on("msg:contact", async (ctx) => {
);
}
log.info(ctx.update.user, "contact spoof attempted");
return ctx.reply("Could not verify sent contact.");
});

View File

@@ -6,7 +6,7 @@ const cache = require("./cache");
const bot = require("./bot");
const log = require("./log");
if (config.get("TELEGRAM_POLLING")) {
if (process.env.NODE_ENV !== "production") {
bot.api.deleteWebhook().then(() => {
log.info("starting bot in polling mode");
bot.start();

View File

@@ -8,6 +8,7 @@ async function proxy(sessionId, phone, input = "") {
url: config.get("USSD_ENDPOINT"),
method: "POST",
parse: "string",
timeout: 3000,
form: {
sessionId: sessionId,
phoneNumber: phone,

View File

@@ -1,5 +1,5 @@
// this regex extracts ussd reply options
const regex = /\s(\d{1,2}).\s/g;
const regex = /\s(\d{1,2})\.\s/g;
// TODO: converts the text to a telegram keyboard
function createKeyboard(input) {

View File

@@ -66,6 +66,4 @@ test("util", (t) => {
t.same(output, expect);
t.end();
});
t.endAll();
});

5055
yarn.lock

File diff suppressed because it is too large Load Diff