cleanup and env changes

Signed-off-by: Naval <ashish.kumar@cloudwick.com>
This commit is contained in:
Naval 2025-03-06 11:06:16 +05:30
parent 70aaf48404
commit 6357db32ee
8 changed files with 75 additions and 130 deletions

View file

@ -8,7 +8,9 @@
"build": "vite build", "build": "vite build",
"build:dev": "vite build --mode development", "build:dev": "vite build --mode development",
"lint": "eslint .", "lint": "eslint .",
"preview": "vite preview" "preview": "vite preview",
"supabase-local": "npx supabase functions serve",
"supabase-deploy": "npx supabase functions deploy"
}, },
"dependencies": { "dependencies": {
"@hookform/resolvers": "^3.9.0", "@hookform/resolvers": "^3.9.0",

View file

@ -264,9 +264,6 @@ policy = "oneshot"
inspector_port = 8083 inspector_port = 8083
# Use these configurations to customize your Edge Function. # Use these configurations to customize your Edge Function.
[functions.send-sms]
# enabled = true
verify_jwt = false
# import_map = "./functions/MY_FUNCTION_NAME/deno.json" # import_map = "./functions/MY_FUNCTION_NAME/deno.json"
# Uncomment to specify a custom file path to the entrypoint. # Uncomment to specify a custom file path to the entrypoint.
# Supported file extensions are: .ts, .js, .mjs, .jsx, .tsx # Supported file extensions are: .ts, .js, .mjs, .jsx, .tsx
@ -275,7 +272,7 @@ verify_jwt = false
# For example, if you want to serve static HTML pages in your function: # For example, if you want to serve static HTML pages in your function:
# static_files = [ "./functions/MY_FUNCTION_NAME/*.html" ] # static_files = [ "./functions/MY_FUNCTION_NAME/*.html" ]
[functions.get-messages] [functions.call-sms-gateway]
verify_jwt = false verify_jwt = false
[analytics] [analytics]

View file

@ -4,3 +4,5 @@ TWILIO_PHONE_NUMBER=+15038377084
SUPABASE_URL=https://ikmbnngahzcellthaysf.supabase.co SUPABASE_URL=https://ikmbnngahzcellthaysf.supabase.co
SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImlrbWJubmdhaHpjZWxsdGhheXNmIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDA1ODY5NjUsImV4cCI6MjA1NjE2Mjk2NX0.puDSeLAaTirOPyj6ndF2Mzzu8CKxlwJsoFP6gK8cWuA SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImlrbWJubmdhaHpjZWxsdGhheXNmIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDA1ODY5NjUsImV4cCI6MjA1NjE2Mjk2NX0.puDSeLAaTirOPyj6ndF2Mzzu8CKxlwJsoFP6gK8cWuA
SMS_ACTIVATE_API_KEY = eA103094961490b3350620b1bdd57244

View file

@ -0,0 +1,68 @@
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'
import { corsHeaders } from '../_shared/cors.ts'
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
serve(async (req) => {
// Handle CORS
if (req.method === 'OPTIONS') {
return new Response('ok', { headers: corsHeaders })
}
if (req.method === 'GET') {
return new Response('ok', { headers: corsHeaders })
}
try {
const { action, selectedService, selectedCountry } = await req.json()
const smsActivateApiKey = Deno.env.get('SMS_ACTIVATE_API_KEY')
if (!smsActivateApiKey) {
throw new Error('Missing platform credentials')
}
if(action != "getActiveActivations" && action != "getNumber"){
throw new Error('Invalid action')
}
if(action === "getNumber" && (!selectedService || !selectedCountry)){
throw new Error('Missing required fields')
}
let apiResponse;
const myHeaders = new Headers();
// myHeaders.append("Cookie", "__cf_bm=ZwMogfNq713s0IM1QbuvaGuJQK0rxRP8AVLa.yU0qYQ-1741017601-1.0.1.1-5KsvD93DDrImkQ.Inrh49z9A_TC_O44Tss_PIAnyp.x6Qfip.qoVL1pWB.MYalVT0oDPalmlcTnleNWGxVPUnGWkqig9lCl6WC.cZPhAxVg");
const requestOptions = {
method: "GET",
headers: myHeaders,
redirect: "follow"
};
switch (action) {
case "getActiveActivations":
await fetch(`https://api.sms-activate.ae/stubs/handler_api.php?api_key=${smsActivateApiKey}&action=getActiveActivations`, requestOptions)
.then((response) => response.text())
.then((result) => apiResponse = result)
.catch((error) => console.error(error));
break;
case "getNumber":
const apiUrl = `https://api.sms-activate.ae/stubs/handler_api.php?api_key=${smsActivateApiKey}&action=getNumber&service=${selectedService}&operator=any&country=${selectedCountry}&maxPrice=0.2250`;
await fetch(apiUrl, requestOptions)
.then((response) => response.text())
.then((result) => (apiResponse = result))
.catch((error) => console.error(error));
break;
default:
break;
}
return new Response(apiResponse, {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 200,
})
} catch (error) {
return new Response(JSON.stringify({ error: error.message }), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 400,
})
}
})

View file

@ -1,3 +0,0 @@
# Configuration for private npm package dependencies
# For more information on using private registries with Edge Functions, see:
# https://supabase.com/docs/guides/functions/import-maps#importing-from-private-registries

View file

@ -1,3 +0,0 @@
{
"imports": {}
}

View file

@ -1,61 +0,0 @@
// Follow this setup guide to integrate the Deno language server with your editor:
// https://deno.land/manual/getting_started/setup_your_environment
// This enables autocomplete, go to definition, etc.
// Setup type definitions for built-in Supabase Runtime APIs
import "jsr:@supabase/functions-js/edge-runtime.d.ts"
import { corsHeaders } from '../_shared/cors.ts'
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
console.log("Hello from Functions!")
Deno.serve(async (req) => {
const { name } = await req.json()
const data = {
message: `Hello ${name}!`,
}
try {
const twilioAccountSid = Deno.env.get('TWILIO_ACCOUNT_SID')
const twilioAuthToken = Deno.env.get('TWILIO_AUTH_TOKEN')
const twilioPhoneNumber = Deno.env.get('TWILIO_PHONE_NUMBER')
if (!twilioAccountSid || !twilioAuthToken || !twilioPhoneNumber) {
throw new Error('Missing Twilio credentials')
}
console.log("env", twilioAccountSid, twilioAuthToken)
const twilioUrl = `https://api.twilio.com/2010-04-01/Accounts/${twilioAccountSid}/Messages.json?PageSize=20`
const response = await fetch(twilioUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Basic ${btoa(`${twilioAccountSid}:${twilioAuthToken}`)}`,
}
})
const result = await response.json()
return new Response(JSON.stringify(result), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 200,
})
} catch (error) {
return new Response(JSON.stringify({ error: error.message }), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 400,
})
}
})
/* To invoke locally:
1. Run `supabase start` (see: https://supabase.com/docs/reference/cli/supabase-start)
2. Make an HTTP request:
curl -i --location --request POST 'http://127.0.0.1:54321/functions/v1/get-messages' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0' \
--header 'Content-Type: application/json' \
--data '{"name":"Functions"}'
*/

View file

@ -1,57 +0,0 @@
import { serve } from 'https://deno.land/std@0.168.0/http/server.ts'
import { corsHeaders } from '../_shared/cors.ts'
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
serve(async (req) => {
// Handle CORS
if (req.method === 'OPTIONS') {
return new Response('ok', { headers: corsHeaders })
}
if (req.method === 'GET') {
return new Response('ok', { headers: corsHeaders })
}
try {
const { phoneNumber, message } = await req.json()
const abc = Deno.env.get('abc')
console.log("abc", abc)
const twilioAccountSid = Deno.env.get('TWILIO_ACCOUNT_SID')
const twilioAuthToken = Deno.env.get('TWILIO_AUTH_TOKEN')
const twilioPhoneNumber = Deno.env.get('TWILIO_PHONE_NUMBER')
if (!twilioAccountSid || !twilioAuthToken || !twilioPhoneNumber) {
throw new Error('Missing Twilio credentials')
}
console.log("env", Deno.env)
const twilioUrl = `https://api.twilio.com/2010-04/Accounts/${twilioAccountSid}/Messages.json`
const response = await fetch(twilioUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Basic ${btoa(`${twilioAccountSid}:${twilioAuthToken}`)}`,
},
body: new URLSearchParams({
To: phoneNumber,
From: twilioPhoneNumber,
Body: message,
}),
})
const result = await response.json()
return new Response(JSON.stringify(result), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 200,
})
} catch (error) {
return new Response(JSON.stringify({ error: error.message }), {
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
status: 400,
})
}
})