@ -60,13 +60,10 @@ Contact.sync();
const User = sequelize . define ( 'User' , {
const User = sequelize . define ( 'User' , {
telegram : {
telegram : {
type : DataTypes . STR ING,
type : DataTypes . INTE GER ,
allowNull : false ,
allowNull : false ,
unique : true ,
unique : true ,
} ,
} ,
hash : {
type : STRING ,
} ,
verification : {
verification : {
type : DataTypes . STRING ,
type : DataTypes . STRING ,
} ,
} ,
@ -130,10 +127,10 @@ function refreshVerification(user, done) {
function createQRCode ( telegram , done ) {
function createQRCode ( telegram , done ) {
User . findOne ( {
User . findOne ( {
where : {
telegram : telegram
}
} )
where : {
telegram : telegram
}
} )
. then ( user => {
. then ( user => {
refreshVerification ( user , result => {
refreshVerification ( user , result => {
const verifyURL = ` ${ process . env . WEBSITE_URL } /#/verify/ ${ encodeURIComponent ( result . verification ) } ` ;
const verifyURL = ` ${ process . env . WEBSITE_URL } /#/verify/ ${ encodeURIComponent ( result . verification ) } ` ;
@ -185,7 +182,10 @@ function addContact(telegram, withUserID, done) {
Contact . create ( { user : user . id , with : withUserID } )
Contact . create ( { user : user . id , with : withUserID } )
. then ( res => {
. then ( res => {
console . log ( ` Registering contact between ${ user . id } and ${ withUserID } ` ) ;
console . log ( ` Registering contact between ${ user . id } and ${ withUserID } ` ) ;
sendTelegramMessage ( withUser . telegram , "Someone scanned your QR code. You will be notified if they are tested positive with Covid. If you are tested positive, please tell this bot /COVIDPOSITIVE" ) ;
sendTelegramMessage ( withUser . telegram ,
"Someone scanned your QR code. You will be notified if they are tested positive with Covid. If you are tested positive, please tell this bot /COVIDPOSITIVE" ,
( ) => { }
) ;
done ( true , "Successfully added contact" ) ;
done ( true , "Successfully added contact" ) ;
} )
} )
. catch ( e => {
. catch ( e => {
@ -203,10 +203,10 @@ function getCookieExpiry() {
function setTelegramWebHook ( done ) {
function setTelegramWebHook ( done ) {
const url = ` https://api.telegram.org/bot ${ process . env . TELEGRAM_TOKEN } /setWebhook ` ;
const url = ` https://api.telegram.org/bot ${ process . env . TELEGRAM_TOKEN } /setWebhook ` ;
axios . post ( url , {
axios . post ( url , {
url : ` ${ process . env . SERVER_API_URL } / ${ process . env . TELEGRAM_SECRET } ` ,
allowed_updates : [ ] ,
drop_pending_updates : true ,
} )
url : ` ${ process . env . SERVER_API_URL } / ${ process . env . TELEGRAM_SECRET } ` ,
allowed_updates : [ ] ,
drop_pending_updates : true ,
} )
. then ( res => { done ( res ) } )
. then ( res => { done ( res ) } )
. catch ( err => { done ( err ) } ) ;
. catch ( err => { done ( err ) } ) ;
}
}
@ -214,9 +214,9 @@ function setTelegramWebHook(done) {
function sendTelegramMessage ( telegramID , message , done ) {
function sendTelegramMessage ( telegramID , message , done ) {
const url = ` https://api.telegram.org/bot ${ process . env . TELEGRAM_TOKEN } /sendMessage ` ;
const url = ` https://api.telegram.org/bot ${ process . env . TELEGRAM_TOKEN } /sendMessage ` ;
axios . post ( url , {
axios . post ( url , {
chat_id : telegramID ,
text : message ,
} )
chat_id : telegramID ,
text : message ,
} )
. then ( ( res ) => {
. then ( ( res ) => {
done ( res )
done ( res )
} )
} )
@ -241,11 +241,8 @@ app.use(session({
app . use ( cors ( { credentials : true , origin : true , secure : true } ) ) ;
app . use ( cors ( { credentials : true , origin : true , secure : true } ) ) ;
app . use ( express . json ( ) )
app . use ( express . json ( ) )
setTelegramWebHook ( ( ) => { } ) ;
setTelegramWebHook ( ( ) => { } ) ;
app . post ( ` / ${ process . env . TELEGRAM_SECRET } ` , ( req , res ) => {
app . post ( ` / ${ process . env . TELEGRAM_SECRET } ` , ( req , res ) => {
if ( req . body . message ) {
sendTelegramMessage ( req . body . message . chat . id , ` ${ req . body . message . text . toUpperCase ( ) } ` , ( res ) => { console . log ( res ) } ) ;
}
res . send ( ) ;
res . send ( ) ;
} ) ;
} ) ;