diff --git a/apps/nativeapp/app/components/phoneInput/PhoneInput.tsx b/apps/nativeapp/app/components/phoneInput/PhoneInput.tsx index 4b5f1c097..7e520707c 100644 --- a/apps/nativeapp/app/components/phoneInput/PhoneInput.tsx +++ b/apps/nativeapp/app/components/phoneInput/PhoneInput.tsx @@ -4,7 +4,7 @@ import PhoneNoInput from 'react-native-phone-number-input'; import {CountryCode} from 'react-native-country-picker-modal'; import {Colors, Typography} from '../../styles'; -import {EXCLUDED_COUNTRIES} from '../../constants'; +import {DISABLE_SMS_COUNTRY_CODE , DISABLE_WHATSAPP_COUNTRY_CODE} from '../../constants'; const IS_ANDROID = Platform.OS === 'android'; @@ -37,10 +37,13 @@ const PhoneInput = ({ const countryCode = phoneInput.current?.getCountryCode(value); valid(checkValid ? checkValid : false); inputValue(formattedValue); - if ( - verificationType === 'Sms' && - EXCLUDED_COUNTRIES.includes(countryCode) - ) { + if (( + verificationType === 'Sms' && + DISABLE_SMS_COUNTRY_CODE.includes(countryCode) + ) || ( + verificationType === 'Whatsapp' && + DISABLE_WHATSAPP_COUNTRY_CODE.includes(countryCode) + )) { destinationFlag(true); return; } else { diff --git a/apps/nativeapp/app/constants/index.tsx b/apps/nativeapp/app/constants/index.tsx index db3b4e9a2..d662cc20d 100644 --- a/apps/nativeapp/app/constants/index.tsx +++ b/apps/nativeapp/app/constants/index.tsx @@ -15,8 +15,8 @@ const POINT_RADIUS_ARR = [ {name: 'Within 1 km', value: 1000}, ]; -// Excluded countries for sms type alert methods -const EXCLUDED_COUNTRIES = [ +// Disable sms and whatsapp alert methods for some countries +const DISABLE_SMS_COUNTRY_CODE = [ 'RU', 'TJ', 'MG', @@ -30,4 +30,8 @@ const EXCLUDED_COUNTRIES = [ 'BZ', ]; -export {WEB_URLS, RADIUS_ARR, POINT_RADIUS_ARR, EXCLUDED_COUNTRIES}; +const DISABLE_WHATSAPP_COUNTRY_CODE = [ + 'IN' +] + +export {WEB_URLS, RADIUS_ARR, POINT_RADIUS_ARR, DISABLE_SMS_COUNTRY_CODE, DISABLE_WHATSAPP_COUNTRY_CODE}; diff --git a/apps/nativeapp/app/screens/Login/Login.tsx b/apps/nativeapp/app/screens/Login/Login.tsx index a8cd7a4df..f8adfba79 100644 --- a/apps/nativeapp/app/screens/Login/Login.tsx +++ b/apps/nativeapp/app/screens/Login/Login.tsx @@ -46,7 +46,7 @@ const Login = () => { prompt: 'login', audience: 'urn:plant-for-the-planet', }, - {ephemeralSession: false}, + {ephemeralSession: false, useLegacyCallbackUrl: true}, ) .then(cred => { const request = { diff --git a/apps/nativeapp/app/screens/Settings/Settings.tsx b/apps/nativeapp/app/screens/Settings/Settings.tsx index 0e9e8c1ca..24c7f1476 100644 --- a/apps/nativeapp/app/screens/Settings/Settings.tsx +++ b/apps/nativeapp/app/screens/Settings/Settings.tsx @@ -61,6 +61,7 @@ import { TrashOutlineIcon, VerificationWarning, DisabledTrashOutlineIcon, + WhatsAppIcon } from '../../assets/svgs'; import {trpc} from '../../services/trpc'; import {Colors, Typography} from '../../styles'; @@ -449,11 +450,11 @@ const Settings = ({navigation}) => { }; // ----------------- handle whatsapp, and Geostationary - // const handleAddWhatsapp = () => { - // navigation.navigate('Verification', { - // verificationType: 'Whatsapp', - // }); - // }; + const handleAddWhatsapp = () => { + navigation.navigate('Verification', { + verificationType: 'Whatsapp', + }); + }; // const handleGeostationary = val => { // let detectionMethods = [...userDetails?.data?.detectionMethods]; @@ -902,7 +903,7 @@ const Settings = ({navigation}) => { )} {/* whatsapp */} - {/* + @@ -966,7 +967,7 @@ const Settings = ({navigation}) => { ))} )} - */} + {/* sms */} diff --git a/apps/nativeapp/app/screens/Verification/Verification.tsx b/apps/nativeapp/app/screens/Verification/Verification.tsx index 5a52b515e..0f574ca50 100644 --- a/apps/nativeapp/app/screens/Verification/Verification.tsx +++ b/apps/nativeapp/app/screens/Verification/Verification.tsx @@ -84,9 +84,21 @@ const Verification = ({navigation, route}) => { ) { return toast.show('Incorrect Number', {type: 'warning'}); } - if (verificationType === 'Sms' && limitDestination) { + if ( + (verificationType === 'Sms' && limitDestination) + ) { + return toast.show( + `Apologies, sms services to your region are currently unsupported. Please select a different method.`, + { + type: 'warning', + }, + ); + } + if ( + (verificationType === 'Whatsapp' && limitDestination) + ) { return toast.show( - 'Destination is restricted due to country limitations', + `Meta's API change in India affects delivery of FireAlerts over WhatsApp. Please select a different method.`, { type: 'warning', }, diff --git a/apps/server/src/Services/Notifier/Notifier/SMSNotifier.ts b/apps/server/src/Services/Notifier/Notifier/SMSNotifier.ts index ed4c89ab2..645230c88 100644 --- a/apps/server/src/Services/Notifier/Notifier/SMSNotifier.ts +++ b/apps/server/src/Services/Notifier/Notifier/SMSNotifier.ts @@ -46,7 +46,7 @@ class SMSNotifier implements Notifier { } // If the destination is a restricted Country, return false, log error. - if (isPhoneNumberRestricted(destination)) { + if (isPhoneNumberRestricted('sms', destination)) { // If destination is a restricted phone number // Then, notification was created before FireAlert introduced SMS Restriction // Thus, notification must be deleted, so that it is not constantly marked as "not-delivered" diff --git a/apps/server/src/pages/api/tests/whatsapp.ts b/apps/server/src/pages/api/tests/whatsapp.ts index 016c20a2c..e3b2bc765 100644 --- a/apps/server/src/pages/api/tests/whatsapp.ts +++ b/apps/server/src/pages/api/tests/whatsapp.ts @@ -40,22 +40,22 @@ export default async function testWhatsApp(req: NextApiRequest, res: NextApiResp const notificationParameters_alert: NotificationParameters = { message: "Fire detected inside Las Americas 7A", subject: "FireAlert", - url: "https://firealert.plant-for-the-planet.org/alert/ed1cf199-6c3a-4406-bac0-eb5519391e2e", + url: "https://firealert.plant-for-the-planet.org/alert/6769f0f5-86cf-4cea-ba27-6e2dc4b58376", id: "notificationId", // authenticationMessage: true, // otp: "12345", - siteName: 'Las Americas', + siteName: 'PROBOSQUE 22', alert:{ - id: "ed1cf199-6c3a-4406-bac0-eb5519391e2e", + id: "6769f0f5-86cf-4cea-ba27-6e2dc4b58376", type: 'fire', confidence: 'high', source: "TEST", date: new Date(), - longitude: 80.45728, - latitude: 66.66537, + longitude: -100.12768, + latitude: 18.72452, distance: 0, - siteId: "siteId1", - siteName: "SiteName", + siteId: "clikwjyg1004ymk0egij2a716", + siteName: "PROBOSQUE 22", data: {}, } }; diff --git a/apps/server/src/server/api/routers/alertMethod.ts b/apps/server/src/server/api/routers/alertMethod.ts index 1e6ec0c13..e8f9d3ae6 100644 --- a/apps/server/src/server/api/routers/alertMethod.ts +++ b/apps/server/src/server/api/routers/alertMethod.ts @@ -71,7 +71,7 @@ export const alertMethodRouter = createTRPCRouter({ const destination = alertMethod.destination const method = alertMethod.method if(method === 'sms'){ - if (isPhoneNumberRestricted(destination)) { + if (isPhoneNumberRestricted('sms', destination)) { throw new TRPCError({ code: 'UNAUTHORIZED', message: `Cannot Verify AlertMethod. ${destination} is restricted due to country limitations.`, @@ -218,11 +218,22 @@ export const alertMethodRouter = createTRPCRouter({ // If Method is sms, restrict phone number to only allowed countries if(input.method === 'sms'){ // Check if the destination falls inside of accepted countries - const isDestinationAccepted = !isPhoneNumberRestricted(input.destination); + const isDestinationAccepted = !isPhoneNumberRestricted('sms', input.destination); if(isDestinationAccepted === false){ throw new TRPCError({ code: 'BAD_REQUEST', - message: `Destination is restricted due to country limitations`, + message: `Phone number is restricted due to country limitations.`, + }); + } + } + // If Method is whatsapp, restrict phone number to only allowed countries + if(input.method === 'whatsapp'){ + // Check if the destination falls inside of accepted countries + const isDestinationAccepted = !isPhoneNumberRestricted('whatsapp', input.destination); + if(isDestinationAccepted === false){ + throw new TRPCError({ + code: 'BAD_REQUEST', + message: `Phone number is restricted due to country limitations.`, }); } } diff --git a/apps/server/src/utils/notification/restrictedSMS.ts b/apps/server/src/utils/notification/restrictedSMS.ts index d077d1ae3..2d537db08 100644 --- a/apps/server/src/utils/notification/restrictedSMS.ts +++ b/apps/server/src/utils/notification/restrictedSMS.ts @@ -3,7 +3,7 @@ import phone from 'phone'; -const restrictedCountryCodes = [ +const restrictedCountryCodesSms = [ 'RU', // Russia 'TJ', // Tajikistan 'MG', // Madagascar @@ -17,8 +17,16 @@ const restrictedCountryCodes = [ 'BZ', // Belize ]; -export const isPhoneNumberRestricted = (phoneNumber: string) => { +const restrictedCountryCodesWhatsapp = [ + 'IN', // India +] + +export const isPhoneNumberRestricted = (alertMethodMethod: string, phoneNumber: string) => { const phoneResult = phone(phoneNumber); const countryCode = phoneResult.countryIso2 as string; - return restrictedCountryCodes.includes(countryCode); + if(alertMethodMethod === 'sms'){ + return restrictedCountryCodesSms.includes(countryCode); + } else if (alertMethodMethod === 'whatsapp'){ + return restrictedCountryCodesWhatsapp.includes(countryCode); + } } \ No newline at end of file