Reputation: 1
I'm developing a web app that allows you to create email signatures for your company. The idea is that once you have your email signature, I want users to be able to click a button and install those signatures to their team members that use Google Workspace.
I've seen other apps achieve this by allowing the Google Workspace admin to install an add-on (from Google Workspace Marketplace) and giving permissions. The add-on has no UI, but it then allows their web apps to install the signatures into each employee.
How can I do this?
I have tried to achieve this by enabling in Google Cloud the Gmail API, Google Workspace Marketplace SDK, Google Workspace Add-ons API, Admin SDK API (among others), and creating an add-on for this. But it doesn't work because I get lost on how to to make my web app effectively send and install the signatures to the Google Workspace employees.
I have also created a JSON deployment, but don't know how to "connect" my app to Google Workspace:
I have also tried to create a service account to get domain-wide delegation (?) but this didn't work.
I have already implemented Google OAuth for user signup/login (with Supabase) and importing contacts from Google Workspace to easily invite your team to my app.
src/routes/api/workspace/signatures/batch/+server.ts
import { json } from '@sveltejs/kit';
import { google } from 'googleapis';
import type { RequestHandler } from '@sveltejs/kit';
export const POST: RequestHandler = async ({ locals: { supabase, user }, request }) => {
console.log('1. Starting batch signature update');
if (!user) {
return json({ error: 'Unauthorized' }, { status: 401 });
}
try {
const body = await request.json();
console.log('2. Request body:', body);
const { teamId } = body;
if (!teamId) {
return json({ error: 'Team ID is required' }, { status: 400 });
}
// Get team members
console.log('3. Fetching team members for team:', teamId);
const { data: teamMembers, error: teamError } = await supabase
.from('team_members')
.select(`
company_members (
user_id,
users ( email )
)
`)
.eq('team_id', teamId);
if (teamError) {
console.error('4. Team members fetch error:', teamError);
return json({ error: 'Failed to fetch team members' }, { status: 400 });
}
if (!teamMembers?.length) {
console.log('4. No team members found');
return json({ error: 'No team members found' }, { status: 400 });
}
console.log('4. Found team members:', teamMembers);
const gmail = google.gmail({ version: 'v1', auth: new google.auth.GoogleAuth() });
// Update signatures
for (const member of teamMembers) {
console.log('5. Processing member:', member);
const userEmail = member.company_members?.[0]?.users?.[0]?.email;
if (!userEmail) {
console.log('Skipping member - no email found');
continue;
}
console.log('6. Fetching signature assignment for:', userEmail);
const { data: assignment, error: assignmentError } = await supabase
.from('signature_assignments')
.select('custom_data')
.eq('assigned_to', member.company_members[0].user_id)
.single();
if (assignmentError) {
console.error('Assignment fetch error:', assignmentError);
continue;
}
if (!assignment) {
console.log('No signature assignment found for:', userEmail);
continue;
}
try {
console.log('7. Updating signature for:', userEmail);
await gmail.users.settings.sendAs.update({
userId: userEmail,
sendAsEmail: userEmail,
requestBody: {
signature: assignment.custom_data.html
}
});
console.log('8. Signature updated successfully for:', userEmail);
} catch (error) {
console.error(`Failed to update signature for ${userEmail}:`, error);
}
}
return json({ success: true });
} catch (error) {
console.error('Error in batch update:', error);
return json({
error: 'Failed to update signatures',
details: error instanceof Error ? error.message : 'Unknown error'
}, { status: 500 });
}
};
I guess what I need the most is guidance on how to achieve what Scribe does here: https://help.scribe-mail.com/scribe/install-signatures/automated-installation/google-workspace-gmail (other apps like WiseStamp, Exclaimer, among others, do this too). Like which tables should I create in Supabase for this, how should I create the add-on in Google Workspace, how should my app communicate with the add-on to install the email signatures to all company members, and so on.
Thank you in advance 🙏
My tech stack:
Upvotes: 0
Views: 36