Skip to content
NewA realistic 3D head for a free swim cap editor
Nov 27, 2026·5 MIN READ
A CRM card inside Gmail with Apps Script, one endpoint and a redirect that lied

A CRM card inside Gmail with Apps Script, one endpoint and a redirect that lied

We turned the Vimek Gmail add-on into a Copper-style sidebar: who the sender is, status, order, deposit, device, quick actions. One backend endpoint, one evening, and a lookup that said 'Not in the CRM' for a real lead.

It started with a small question: how do I send a teammate "the Gmail plugin" so he can install it in Chrome? The answer was that there is no plugin. Vimek Gmail is a Google Workspace add-on written in Apps Script, it installs per Google account, and until today it did one thing: send the open thread to our agent and show the answer. While looking at it I asked for the thing I missed from Copper CRM years ago: open an email and see who this person is, without asking anyone.

What the card shows

One GET /api/v1/vimek/contacts/?email= to the Vimo Swim backend, drawn with plain CardService widgets. No AI on this path.

Known lead

Pipeline, purchase and tester status, source and campaign, contact details, order and paid flag, deposit, device, owner. Buttons open the CRM, the lead's Slack channel, Chatwoot and WhatsApp.

Unknown sender

One line that says no lead has this address, plus newsletter and shop history, and an Add-as-a-lead form prefilled from the email.

Quick actions

Change the pipeline status or append a dated note. Both go through the write endpoints Vimek already uses from Slack, with my Google email as the person who changed it.

Ask Vimek

The old prompt moved to the bottom of the card. The agent is for questions, the card is for facts.

flowchart LR
    G[Gmail message opens] --> A["Apps Script<br/>onGmailMessageOpen"]
    A -->|"Api-Key"| B["backend<br/>/vimek/contacts/?email="]
    B --> C["CRM lead, deposit,<br/>devices, shop orders"]
    A --> D[Card in the side panel]
    D -->|"Save status, Add note"| E["PATCH /vimek/leads/id/"]

The backend side is one read-only view that reuses the lead_details helper the agent's tools already had, plus owner, links and the five latest timeline entries. Lead emails are not unique in our CRM, so the newest match wins and the response carries a count of the others. The sender header comes in as Name <addr>, so email.utils.parseaddr runs first. Ten tests, one regenerated OpenAPI file.

Mockup first

Before any code I built a design canvas with five artboards: Gmail with the panel open, the four panel states at the real 320 px width. That hour paid for itself twice. It forced the list of fields, and it showed that a lead has no owner field, which was added to the CRM the same afternoon in another ticket.

Shipping without clasp

The add-on is pushed with clasp, and clasp was not logged in on this Mac. Logging in means a Google OAuth flow in the browser, which I leave to a person. The Apps Script web editor was already signed in, so I used that instead.

The Apps Script editor is Monaco, and the page exposes monaco on window. monaco.editor.getModels() lists the files, model.setValue(code) replaces one, and the Save button writes them. I checked each file with a SHA-256 of getValue() after a reload against the local build. Three files, three matching hashes.

The installed test deployment runs the head code, so the save was live in Gmail at once. That is also where the evening got interesting.

The redirect that lied

The backend pull request was not merged yet, so /vimek/contacts/ did not exist in production. Django's admin lives at the root of that host and catches every unknown path with a redirect to the login page. UrlFetchApp follows redirects by default. My request helper got a 200 with an HTML body, my "tolerant" JSON parser turned that into an empty object, and the card did exactly what it does for an empty answer: it said Not in the CRM for a real lead, with a friendly form to add him again.

Backend stateHTTPOld cardNew card
Endpoint live, lead found200Contact cardContact card
Endpoint live, no lead200Add as a leadAdd as a lead
Endpoint missing302Add as a leadRed error line, Ask still works
Proxy error page502CrashRed error line, Ask still works

"Not found" and "could not look" are two different states. A lookup that cannot answer has to fail loudly, never return an empty result. The fix was three lines: followRedirects: false, a non-JSON body is an error whatever the status, and anything from 300 up is an error with the URL in the message.

The automated security review on the commit was useful too: CRM text is now escaped before it lands in card HTML, only https links get a button, and the lead id a button carries is checked before it goes into a URL.

Two pull requests on the backend, one on the add-on, one evening with Claude Code doing the typing and me doing the clicking. What I would do differently: deploy the backend first and watch the card fail honestly, instead of designing an error path that was friendly enough to be wrong.

Share
Mariusz Smenżyk
Written by

Mariusz Smenżyk

Builder for sport. Make. Test. Launch.

Related notes