Supabase
Supabase is an open-source Backend-as-a-Service (BaaS) platform that offers a robust alternative to Firebase. It comes packed with a wide array of tools for app development, featuring a PostgreSQL relational database, user authentication, storage, real-time subscriptions, and Edge Functions. You can choose to host everything yourself or take advantage of their managed cloud services. Unlike Firebase, which utilizes a NoSQL database, Supabase harnesses the strengths of SQL through PostgreSQL, enabling you to create complex data relationships and run intricate queries.
To send SMS messages via seven, you only need to make a few adjustments. The work involved takes about ten minutes and can be done without extensive technical knowledge.
Prerequisites
- An API key from seven - can be created in the developer dashboard
- Supabase
Usage
- 1
Create secrets
- Open the Supabase dashboard and navigate to Edge Functions -> Secrets
- In the Add new secrets section, create a key pair named SEVEN_API_KEY with your API key as the value
- Confirm with Save
- 2
Create an edge function
-
Navigate to Edge Functions -> Functions and click Deploy a new function -> Via Editor.
-
Enter a meaningful name, e.g. sms-hook.
-
Paste the following code into the editor:
import 'jsr:@supabase/functions-js/edge-runtime.d.ts'; Deno.serve(async (req) => { try { const payload = await req.json(); const { user, sms } = payload; const body = { text: `Dear customer, your verification code is: ${sms.otp}`, to: user.phone }; const resp = await fetch('https://gateway.seven.io/api/sms', { body: JSON.stringify(body), method: 'POST', headers: { Accept: 'application/json', 'X-Api-Key': Deno.env.get('SEVEN_API_KEY') } }); const response = await resp.json(); console.log('response', response); if (response.success === '100') { return new Response(JSON.stringify({ message: 'SMS sent successfully' }), { status: 200, headers: { 'Content-Type': 'application/json' } }); } return new Response(JSON.stringify({ error: { http_code: response.succcess, message: `Failed to send SMS: ${response.succcess}.` } }), { status: resp.status, headers: { 'Content-Type': 'application/json' } }); } catch (err) { console.error(err); return new Response(JSON.stringify({ error: { http_code: 500, message: `Failed to send sms: ${JSON.stringify(err)}` } }), { status: 500, headers: { 'Content-Type': 'application/json' } }); } });
-
Click on Deploy function
-