<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Steve Bazyl on Medium]]></title>
        <description><![CDATA[Stories by Steve Bazyl on Medium]]></description>
        <link>https://medium.com/@sqrrrl?source=rss-c3f6d0330ec0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*pmkvDllRE-k6ZFZU.jpg</url>
            <title>Stories by Steve Bazyl on Medium</title>
            <link>https://medium.com/@sqrrrl?source=rss-c3f6d0330ec0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 08:57:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sqrrrl/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Unexpected Complexity with Google Meet and Calendar APIs]]></title>
            <link>https://sqrrrl.medium.com/unexpected-complexity-with-google-meet-and-calendar-apis-ac5f745ea310?source=rss-c3f6d0330ec0------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac5f745ea310</guid>
            <category><![CDATA[google-meet-api]]></category>
            <category><![CDATA[google-workspace]]></category>
            <category><![CDATA[google-calendar]]></category>
            <category><![CDATA[google-calendar-api]]></category>
            <dc:creator><![CDATA[Steve Bazyl]]></dc:creator>
            <pubDate>Wed, 24 Jul 2024 20:12:18 GMT</pubDate>
            <atom:updated>2024-07-31T19:38:06.977Z</atom:updated>
            <content:encoded><![CDATA[<p>Over the past few months there’s been a use case that’s been nagging me. A few developers I’ve worked with have mentioned it in passing, but it never struck me as anything more than an annoyance. It came up again just the other day and I finally decided to dig in and see what all the fuss was about.</p><p>The question is two-fold:</p><ul><li>Given a <a href="https://developers.google.com/meet/api/reference/rest/v2/conferenceRecords">conference record</a> in the <a href="https://developers.google.com/meet">Meet API</a>, what was the corresponding <a href="https://developers.google.com/calendar/api/v3/reference/events">event</a> in the <a href="https://developers.google.com/calendar">Calendar API</a>?</li><li>Given a calendar event, what’s the corresponding conference record in the Meet API?</li></ul><p>On the surface, it seems like these should be easy questions to answer.</p><p>Turns out, it’s not.</p><h3>Togetherness</h3><p>Before jumping in, why try and make these correlations in the first place?</p><p>A lot of early adopters of the Meet API are building meeting analytics for sales, events, and other verticals. In those cases, a comprehensive view of meetings is needed, and neither the Calendar API nor the Meet API alone suffices.</p><p>The Calendar API is great at addressing the essential who, what, when, where, and why questions of what *will* happen. The Meet API, on the other hand, tells us what *actually* happened and provides details like when people joined and left and recordings and transcripts that detail what was discussed.</p><p>There’s some overlap between them, but at the end of the day merging gives a much better picture than either in isolation.</p><h3>A Simple Plan</h3><p>Let’s start with the ideal case. There’s an event in Google Calendar with Meet enabled. It’s a single event and the meeting starts and ends on time. We have a 1:1 relationship between the event and the corresponding record created after the meeting happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*0d-Jd4YVnWoMq2tpmcB90Q.png" /></figure><p>Given the calendar event, retrieving the conference record is straight forward:</p><ul><li>Look up the meeting space using the meeting code on the event.</li><li>Retrieve the conference records.</li><li>Take the first one found.</li></ul><p>The other way around is a little more complicated, but doable:</p><ul><li>Retrieve the corresponding meeting space for the conference record.</li><li>Query the Calendar API for events approximately at the time of the record (+/- some reasonable slop).</li><li>Find the event containing the meeting code</li></ul><p>You might be thinking “Steve, this isn’t that hard, what could <em>possibly</em> go wrong?”</p><p>Everything.</p><p>While at a product level, Meet and Calendar appear well integrated, underneath the covers it’s a different story. The coupling between a calendar event and a meeting space is a very tenuous one and even more so when it comes to conference records.</p><p>People do all sorts of unexpected things. And it doesn’t help that conference records are defined as the period from when the first person joins a meeting space to when the last person leaves. Or that people can muck with Calendar in unexpected ways.</p><p>So what kind of things can people do that ruin our day? And how bad does it get?</p><h4>White Rabbit</h4><p>I’m not a punctual person. I know, I know. I’m just so absolutely amazing and perfect in every other way how could that possibly be?!</p><p><em>..Ahem…</em></p><p>OK, back to reality.</p><p>And reality is I’m often late. In my efforts to not <em>appear</em> late, I’ll sometimes join a meeting on my phone while I’m on my way to a meeting room or my desk at home. Fortunately a lot of other people I meet with are often late too, and that gives me an opportunity to switch devices before anyone notices.</p><p>Whew!</p><p>Except Meet <em>did</em> notice. And that brief time where I joined and then promptly left leaves a conference record which is then followed up by a new one when I rejoin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*QsBhF8wuQvhJ3cY_YhuwNw.png" /></figure><p>This creates a problem for our previously simple algorithms for matching events and conference records. I now have <em>two</em> records that correlate to the same event and need a way to distinguish between them.</p><p>In this particular case, there are some heuristics we can use to distinguish between them and can filter the conference records to help us make the choice. We can look at things like:</p><ul><li>Overall duration or overlap with the event</li><li>Number of participants</li><li>Presence of artifacts</li></ul><p>In other words, if we’re presented with a 28 minute meeting with 5 participants and a 2 minute one with just one person, it’s obvious what the right answer is.</p><h4>Deja Vu</h4><p>Unintentional conference records are one thing. But what about intentional ones? What if I need to keep coming back to the same meeting over and over and over again?</p><p>I recently had the joy (no sarcasm, I swear!) of participating in a 2 day design sprint where we were coming up with some amazing demo ideas for our next round of conferences. These were long days with a distributed team. We took breaks, had lunch, and split into breakout rooms at various points. For Calendar this was appropriately one big event. Meet saw things differently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*f0H74zKiP0QL00S14Y45tw.png" /></figure><p>While we can filter and discard clearly invalid events as in the previous example, we can’t necessarily filter the conference records down to a single item in all cases. Here, each is valid and considered part of a single logical event.</p><h4>Time Bandits</h4><p>Recurring meetings aren’t fundamentally different from single meetings. Fortunately Calendar doesn’t allow recurring meetings any more frequently than daily, otherwise endless back-to-back meetings would really ruin our day. But I digress.</p><p>Normally we’d do the same thing for recurring meetings and ask the Calendar API to expand things so we can find the individual event instance.</p><p>So let’s imagine I’m on my weekly Wednesday morning call with a partner and at the end of the meeting they ask “Hey, can we move this to Thursday?”</p><p>Sure. I go into Calendar and move the meeting to Thursday. Calendar then asks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/0*c3GA8qoJqSLFWxV9" /></figure><p>And in my infinite stupidity, I select <strong>“All events”</strong>.</p><p>Yep, that’s right. It’s possible to retroactively reschedule recurring events. Thanks, Calendar. Thanks.</p><p>At the beginning I mentioned we needed a little bit of slop when searching for calendar events. Hopefully we all realized that meetings can start a little early or a little late and we need to cast a little bit of a wide net. If you’re like me, you were probably thinking +/- an hour would be plenty of time.</p><p>Ummm…. So how do we handle cases when all the previous events have shifted by an entire day? Or more?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*RoypW0DFUUR3GcWRD0j-YQ.png" /></figure><p>If we’re lucky, we can ignore calendar events entirely. Conference records are created after the fact and are definitive. We <em>know</em> something happened at that time, even if Calendar thinks otherwise.</p><p>Oh. And it’s not only recurring events. Even single events can be retroactively rescheduled. So if we need the event data, the best approach is to watch Calendar and try to capture events <em>before</em> they happen.</p><ul><li>Set up a <a href="https://developers.google.com/calendar/api/v3/reference/events/watch">watch</a> on events to capture new events and updates.</li><li>Store the event ID &lt;-&gt; meeting code mapping in a separate store. For recurring events, this would be to the original event with the recurrence rules.</li></ul><p>This gets us most of the way there. For single events it works great and allows us to directly look up the event. Recurring events mostly work, at least if we store the original event with the recurrence rules.</p><p>There’s one edge case that isn’t easily handled. For recurring events, if an individual instance has been modified to add additional details it may not be possible to find the specific instance. Tracking the schedule changes as a way to reconstruct history might work, but that opens up a new set of issues. I’d love to hear your thoughts here and see what other options might work.</p><h4>Clone Wars</h4><p>Remember how I was relieved that Calendar doesn’t allow back-to-back recurrences and how that would completely ruin our day?</p><p>About that…</p><p>One thing Calendar allows, though, is changing the meeting code for a meeting.</p><p>As a manager, I want to schedule a bunch of one-on-ones in a block. And since my team is all over the place and I don’t want to keep bouncing between meetings, I just set them all to the same meeting:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/0*2Og8XDOkBvyraTXv" /></figure><p>Now I have the luxury of joining once and hanging out while others pop in and out at their scheduled times.</p><p>But we have the opposite of our earlier problems — a single conference record that correlates to three different calendar events.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*90qV07ptVFTmpE8FP4cfBw.png" /></figure><p>Other than telling users “don’t do that” there’s not a lot we can do here other than fail. In most cases it would be wrong to try and correlate these in a meaningful way. A careful user may toggle recordings between each segment which would generate separate artifacts. It’s possible to use the <a href="https://developers.google.com/meet/api/reference/rest/v2/conferenceRecords.recordings">recordings</a> and <a href="https://developers.google.com/meet/api/reference/rest/v2/conferenceRecords.transcripts">transcripts</a> in the Meet API to distinguish between events, but the same sorts of challenges we have for conference records applies there as well.</p><p>Tread lightly here.</p><h4>Everything Everywhere All at Once</h4><p>To make matters worse, these aren’t mutually exclusive events.</p><p>The busy manager that I am, I’m late to my block of 1:1’s that all share the same meeting code and create a false conference record then decide to move them all to another day and retroactively apply to all past events…</p><p>Suddenly, all of space and time collapses and….well, at least it’s not my problem anymore.</p><p>In the end, it turns out that a lot of assumptions that are easy to make about how calendar events and conference records correlate simply aren’t true. It’s not the clean 1-to-1 mapping that we’d *like* it to be. It can be a messy many-to-many mapping littered with ambiguity. And there are cases I didn’t even mention like somebody flat out deleting calendar events.</p><p>Sigh.</p><h3>A New Hope</h3><p>While lots of things <em>can</em> go wrong, it doesn’t mean that they <em>will</em>. A best effort approach that expects the happy path works just fine, at least most of the time. These scenarios are likely to be rare or non-existent events in practice.</p><p>Code defensively and when in doubt fall back on asking the user to choose or just say “I don’t know” and move on.</p><p>And since I’ve thrown in more than enough movie titles, time for me to move on too</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac5f745ea310" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Content generation with Google Workspace Add-ons]]></title>
            <link>https://sqrrrl.medium.com/content-generation-with-google-workspace-add-ons-dc46691dda2a?source=rss-c3f6d0330ec0------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc46691dda2a</guid>
            <category><![CDATA[google-workspace]]></category>
            <category><![CDATA[google-docs-add-on]]></category>
            <category><![CDATA[g-suite]]></category>
            <category><![CDATA[google-apps-script]]></category>
            <dc:creator><![CDATA[Steve Bazyl]]></dc:creator>
            <pubDate>Wed, 21 Oct 2020 21:33:21 GMT</pubDate>
            <atom:updated>2020-10-21T21:33:21.121Z</atom:updated>
            <content:encoded><![CDATA[<p>Back when G Suite, err… Google Workspace Add-ons launched, support for Docs, Sheets, and Slides was conspicuously absent. Sure, they’ve long supported their own flavor of add-ons, but the idea of building an add-on two different ways didn’t sit well with me. Thankfully I didn’t have to wait too long for the editors to catch up. I know it <em>felt</em><strong><em> </em></strong>like an eternity, but let’s just chalk that up to 2020 being what it is.</p><p>Now that <a href="https://developers.google.com/gsuite/add-ons/overview">add-ons work in the editors</a> I had the chance to build a few small demos to try them out. The two samples I built both fall into the category of content generation. One inserts text, the other images. There are <em>lots</em> of potential add-ons that do exactly this — inserting generated charts or diagrams for a report or sales pitch, grabbing images from a stock photography catalog for a slide deck, adding canned snippets of text for an RFP, or using AI-driven text generation and summarization to accelerate writing.</p><p>As fun as building some of those might be, I wanted to build something simple that shows what <em>could</em> be done without going down too deep a hole. For text, what better way to show inserting text than the classic Lorem Ipsum! Ok ok ok… To be fair, Pirate Ipsum, Zombie Ipsum, Cat Ipsum or one of the many <a href="https://digital.com/lorem-ipsum-generators/">other variants</a> <em>would</em> be better, but I’m sticking with the classics for this one.</p><p>For images, I went with something more useful — QR Codes. They’re simple to generate and there are plenty of good reasons for adding them to a document or presentation, even emails. But even if you don’t care about random placeholder text or QR codes, it’s just a small jump from these to inserting whatever text or image content matters to you.</p><p>Let’s jump into how they’re built.</p><h3>Enable the editors in the Apps Script manifest</h3><p>All add-ons start with a manifest that describes the features and entry points. For the editors, only the homepageTrigger entry points are supported. Since the home page runs in the context of an active editing session, there’s naturally more context available than in other hosts — the document itself.</p><pre>&quot;docs&quot;: {<br>  &quot;homepageTrigger&quot;: {<br>    &quot;runFunction&quot;: &quot;onHomepage&quot;<br>  }<br>},<br>&quot;sheets&quot;: {<br>  &quot;homepageTrigger&quot;: {<br>   &quot;runFunction&quot;: &quot;onHomepage&quot;<br>  }<br>},<br>&quot;slides&quot;: {<br>  &quot;homepageTrigger&quot;: {<br>    &quot;runFunction&quot;: &quot;onHomepage&quot;<br>  }<br>},<br>&quot;gmail&quot;: {<br>  &quot;composeTrigger&quot;: {<br>    &quot;draftAccess&quot;: &quot;NONE&quot;,<br>    &quot;selectActions&quot;: [{<br>      &quot;runFunction&quot;: &quot;onHomepage&quot;,<br>      &quot;text&quot;: &quot;Insert QR Code&quot;<br>    }]<br>  }<br>}</pre><p>As an aside, there’s a bit of duplication here and I could just have easily used a single homepage trigger for the entire add-on:</p><pre>&quot;common&quot;: {<br>    &quot;homepageTrigger&quot;: {<br>    &quot;runFunction&quot;: &quot;onHomepage&quot;<br>    }<br>},<br>&quot;docs&quot;: {},<br>&quot;sheets&quot;: {},<br>&quot;slides&quot;: {},<br>&quot;gmail&quot;: {<br>    ...<br>}</pre><p>But since these two add-ons <strong>only</strong> work contextually, I thought it best to define the entry points on a per-host basis.</p><h3>Request permissions</h3><p>The other important part is listing the scopes the add-on needs.</p><pre>&quot;oauthScopes&quot;: [<br>  &quot;<a href="https://www.googleapis.com/auth/documents.currentonly">https://www.googleapis.com/auth/documents.currentonly</a>&quot;,<br>  &quot;<a href="https://www.googleapis.com/auth/presentations">https://www.googleapis.com/auth/presentations</a>&quot;, <br>  &quot;<a href="https://www.googleapis.com/auth/spreadsheets">https://www.googleapis.com/auth/spreadsheets</a>&quot;,<br>  &quot;<a href="https://www.googleapis.com/auth/script.external_request">https://www.googleapis.com/auth/script.external_request</a>&quot;,<br>  &quot;<a href="https://www.googleapis.com/auth/gmail.addons.execute">https://www.googleapis.com/auth/gmail.addons.execute</a>&quot;,<br>  &quot;<a href="https://www.googleapis.com/auth/gmail.addons.current.action.compose">https://www.googleapis.com/auth/gmail.addons.current.action.compos</a>e&quot;<br>],<br></pre><p>In this case the add-on needs access to update the documents. Gmail needs some special scopes unique to compose-time add-ons as well. Lastly, the external_request scope allows calling the underlying web APIs that generate the lorem ipsum text and QR codes. I’m lazy and even with the new V8 runtime, it’s often a chore trying to get Node.js packages to run in Apps Script. Yes, they’re both JavaScript and both use V8, but the environments are very different. Calling an API with <a href="https://developers.google.com/apps-script/reference/url-fetch">UrlFetchApp</a> is much easier, so <a href="https://loripsum.net/">https://loripsum.net/</a> and <a href="http://goqr.me/api/">http://goqr.me/api/</a> to the rescue!</p><p>There’s more to the manifest, but it’s mostly cosmetic details. You can view the full version for both add-ons on <a href="https://github.com/gsuitedevs/add-ons-samples">GitHub</a>.</p><h3>Display the home card</h3><p>Both add-ons require the user to enter some information and confirm inserting content — how much text to generate or the data to encode in the QR code. They’re both very similar, so let’s just take a look at one of them — the lorem ipsum generator</p><pre>function onHomePage(event) {<br>  let builder = CardService.newCardBuilder();</pre><pre>  let numParagraphsInput = CardService.newTextInput()<br>    .setTitle(&#39;Number of paragraphs&#39;)<br>    .setFieldName(&#39;paragraphs&#39;)<br>    .setHint(&#39;Enter # of paragraphs to generate&#39;)<br>    .setValue(&#39;1&#39;);<br>  <br>  let lengthInput = CardService.newSelectionInput()<br>    .setTitle(&#39;Average length of paragraph&#39;)<br>    .setFieldName(&#39;length&#39;)<br>    .setType(CardService.SelectionInputType.DROPDOWN)<br>    .addItem(&#39;Short&#39;, &#39;short&#39;, true)<br>    .addItem(&#39;Medium&#39;, &#39;medium&#39;, false)<br>    .addItem(&#39;Long&#39;, &#39;long&#39;, false)<br>    .addItem(&#39;Very long&#39;, &#39;verylong&#39;, false);<br>           <br>  let submitAction = CardService.newAction()<br>    .setFunctionName(&#39;onGenerateText&#39;)<br>    .setLoadIndicator(CardService.LoadIndicator.SPINNER);<br>  let submitButton = CardService.newTextButton()<br>    .setText(&#39;Generate and insert text&#39;)<br>    .setOnClickAction(submitAction);<br>  <br>  let optionsSection = CardService.newCardSection()<br>    .addWidget(numParagraphsInput)<br>    .addWidget(lengthInput)<br>    .addWidget(submitButton);</pre><pre>  builder.addSection(optionsSection);<br>  return builder.build();<br>}</pre><p>On submitting the form, the action callback is called.</p><pre>function onGenerateText(e) {<br>  let options = {<br>    paragraphs: e.formInput.paragraphs,<br>    length: e.formInput.length<br>  };<br>  // Insert content....<br>}</pre><p>Again, the QR code version is very similar, just a different set of options for the data to encode and requested image size.</p><h3>Insert text and images</h3><p>Here’s where things get a little tricky. Inserting content varies a lot depending on the host application. The add-on event indicates which application is the host for the add-on and the add-on can switch implementations on that value. Inserting text in any individual host isn’t<em> </em>a lot of code, but to be honest, having to write so many variations of nearly identical code bothers me. There certainly are use cases where I’d <em>want</em> the ability to precisely control the behavior for each host, but for this one? Nope, rather have some <a href="https://www.youtube.com/watch?v=0MEIqWQsBrg">little helpers</a> do the work for me.</p><p>For text insertion, it ends up looking like this.</p><pre>let content = &#39;&#39;;<br>switch (e.hostApp) {<br>case &#39;docs&#39;: <br>  let doc = DocumentApp.getActiveDocument()<br>  let cursor = doc.getCursor();<br>  if (!cursor) {<br>    return notify(&#39;Unable to insert text, no cursor.&#39;);<br>  }<br>  content = generateText({ style: &#39;plaintext&#39;, ...options});<br>  cursor.insertText(content);<br>  return notify(&#39;Text inserted&#39;);<br>case &#39;slides&#39;:<br>  let slides = SlidesApp.getActivePresentation();<br>  let textRange = slides.getSelection().getTextRange();<br>  if (!textRange) {<br>    return notify(&#39;Unable to insert text, no cursor.&#39;);<br>  }<br>  content = generateText({ style: &#39;plaintext&#39;, ...options});<br>  textRange.insertText(0 ,content);<br>  return notify(&#39;Text inserted&#39;);<br>case &#39;sheets&#39;:<br>  let sheets = SpreadsheetApp.getActiveSpreadsheet();<br>  let cell = sheets.getCurrentCell();<br>  if (!cell) {<br>    return notify(&#39;Unable to insert text, no cursor.&#39;);<br>  }<br>  content = generateText({ style: &#39;plaintext&#39;, ...options});<br>  cell.setValue(content);<br>  return notify(&#39;Text inserted&#39;);<br>case &#39;gmail&#39;:<br>  content = generateText({style: &#39;html&#39;, ...options});<br>  let updateAction = CardService.newUpdateDraftBodyAction()<br>    .addUpdateContent(content, CardService.ContentType.MUTABLE_HTML)<br>    .setUpdateType(CardService.UpdateDraftBodyType.IN_PLACE_INSERT)<br>  return CardService.newUpdateDraftActionResponseBuilder()<br>      .setUpdateDraftBodyAction(updateAction)<br>      .build();<br>default:<br>  return notify(&#39;Host app not supported.&#39;);<br>}</pre><p>Images are very similar:</p><pre>let imageUrl = generateQrCodeUrl(data, width);<br>let image;<br>switch (e.hostApp) {<br>case &#39;docs&#39;: <br>  let doc = DocumentApp.getActiveDocument()<br>  let cursor = doc.getCursor();<br>  if (!cursor) {<br>    return notify(&#39;Unable to insert image, no cursor.&#39;);<br>  }<br>  image = UrlFetchApp.fetch(imageUrl);<br>  cursor.insertInlineImage(image);<br>  return notify(&#39;QR code inserted&#39;);<br>case &#39;slides&#39;:<br>  let slides = SlidesApp.getActivePresentation();<br>  let page = slides.getSelection().getCurrentPage();<br>  if (!page) {<br>    return notify(&#39;Unable to insert image, no page selected.&#39;);<br>  }<br>  image = UrlFetchApp.fetch(imageUrl);<br>  page.insertImage(image)<br>  return notify(&#39;QR code inserted&#39;);<br>case &#39;sheets&#39;:<br>  let sheets = SpreadsheetApp.getActiveSpreadsheet();<br>  let cell = sheets.getCurrentCell();<br>  if (!cell) {<br>    return notify(&#39;Unable to insert image, no cursor.&#39;);<br>  }<br>  image = UrlFetchApp.fetch(imageUrl);<br>  cell.getSheet().insertImage(<br>      image, <br>      cell.getColumn(),<br>      cell.getRow());<br>  return notify(&#39;QR code inserted&#39;);<br>case &#39;gmail&#39;:<br>  let html = `&lt;img style=&quot;display: block&quot; src=&quot;${imageUrl}&quot;/&gt;`;<br>  let updateAction = CardService.newUpdateDraftBodyAction()<br>    .addUpdateContent(content, CardService.ContentType.MUTABLE_HTML)<br>    .setUpdateType(CardService.UpdateDraftBodyType.IN_PLACE_INSERT)<br>  return CardService.newUpdateDraftActionResponseBuilder()<br>      .setUpdateDraftBodyAction(updateAction)<br>      .build();<br>default:<br>  return notify(&#39;Host app not supported.&#39;);<br>}</pre><p>In both cases, Gmail is a bit of an outlier. Interaction isn’t via the built-in APIs in <a href="https://developers.google.com/apps-script">Apps Script, </a>but rather through returning a response from the action instructing the host app to do the work for us.</p><p>Similarly, while the other hosts expect the actual image content as a Blob, Gmail requires an HTML &lt;img&gt; tag. Compose-time actions in Gmail don’t support adding attachments and data URIs aren’t allowed in images either. This means the image must be served from a publicly accessible URL. That’s not a problem in this case since the QR code API can be used as the source for the image, but it’s not hard to imagine cases where add-ons will need to host their generated images in a GCS bucket or elsewhere.</p><h3>Watch out for icebergs</h3><p>Easy, right? Sort of.</p><p>Yes, the implementations here are straightforward. With the exception of Gmail which contains a tiny bit of HTML, this is all plain text and single images. Inserting richly formatted text is more complicated, particularly when the text is already in a format like HTML or markdown. That means parsing and transforming the markup into the right set of API calls for the host app.</p><p>Similarly, replacing text that is selected text is slightly different than inserting text at the cursor. It’s doable, just another use case to be aware of when building and testing an add-on. Neither of these two add-ons demanded that as a feature, but yours might.</p><h3>Next up</h3><p>While inserting content covers a broad range of add-ons for editors, it’s just part of the overall landscape. Consuming and transforming content are also powerful patterns that fit a wide variety of use cases — readability scoring, toxicity or tone analysis, data loss prevention, publishing, and so on. Stay tuned for more, and in the meantime learn more about how to build an <a href="https://developers.google.com/gsuite/add-ons/editors/gsao/building-editor-interfaces">add-on here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc46691dda2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ephemeral Apps with Apps Script and App Maker: The Perfect Use Case]]></title>
            <link>https://sqrrrl.medium.com/ephemeral-apps-with-apps-script-and-app-maker-the-perfect-use-case-377e8727b7f0?source=rss-c3f6d0330ec0------2</link>
            <guid isPermaLink="false">https://medium.com/p/377e8727b7f0</guid>
            <category><![CDATA[google-apps-script]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[google-app-maker]]></category>
            <dc:creator><![CDATA[Steve Bazyl]]></dc:creator>
            <pubDate>Thu, 25 Apr 2019 16:58:31 GMT</pubDate>
            <atom:updated>2019-04-25T16:58:31.282Z</atom:updated>
            <content:encoded><![CDATA[<p>Back in December I had a conversation with a coworker (and all-around awesome person), <a href="https://medium.com/@eric_koleda">Eric Koleda</a> about the future of <a href="http://developers.google.com/apps-script">Apps Script</a>. During the conversation he made a curious claim — that once you write a script, you can “set it and forget it.” It would continue to run forever without having to worry about it breaking. It’s neither a radical idea nor completely unprecedented, but something about the notion bothered me.</p><p>The software developer in me knows that maintaining software is a lot of work — and what the consequences of ignoring it can be. Bit rot happens, because the world changes even if the code doesn’t. Lingering security vulnerabilities in unmaintained systems have been exploited by hackers to create botnets, distribute malware, etc. Developers are steeped in tools designed to ease the burden of maintaining software, and those tools are conspicuously absent in Apps Script.</p><p>I can go on about why maintaining software, and Apps Script in particular, is hard. But the truth is that Apps Script isn’t meant for software developers who spend countless hours designing, building, and maintaining software with all this in mind.</p><p>And that, of course, was Eric’s point. The people who write scripts just want to get something done quickly and have neither the time nor expertise to babysit their scripts.</p><p>Still, many scripts are about processes — human processes. We’re automating things that we would otherwise manually do. In the real world processes change and evolve for countless reasons. People come and go. Regulations and policies add new requirements. A script written a year ago might no longer be appropriate and may even be doing real harm.</p><p>So where does that leave using Apps Script?</p><p>The sweet spot for Apps Script, for me at least, is ephemeral apps. These are apps meant to solve an immediate problem with a short lifetime. Think organizing an event, analyzing a specific set of data, etc. These are all well-defined and simple problems with a clear end goal.</p><p>As a software developer conditioned to think about maintenance, thinking of scripts as throwaway is incredibly <em>liberating</em>. All those nagging thoughts about how to do things “the right way<em>”</em> don’t matter. There is no right way, just good enough. I can be lazy and undisciplined (and let’s be honest, I am!).</p><p>The best part is Apps Script is designed exactly for this type of quick and dirty problem solving. It’s genuinely easy to create a script and start running code in Google’s cloud. No tools needed, just your Google account and a browser.</p><p>Of course this doesn’t mean you shouldn’t use Apps Script (or App Maker) to build more complex solutions or automate long term workflows. Automation is a wonderful thing for saving precious time. Just understand that maintenance is still required and you need to plan for it. Even if Google <em>never</em> changes an API or turns down a service again (ahem…), chances are the assumptions you have to make when writing it will.</p><p>And yes, I’ll happily waste hours arguing with you about the importance of well-maintained applications :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=377e8727b7f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to waste time and abuse Google Sheets for personal amusement]]></title>
            <link>https://sqrrrl.medium.com/how-to-waste-time-and-abuse-google-sheets-for-personal-amusement-86c57597a478?source=rss-c3f6d0330ec0------2</link>
            <guid isPermaLink="false">https://medium.com/p/86c57597a478</guid>
            <category><![CDATA[google-sheets]]></category>
            <category><![CDATA[google-sheets-api]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Steve Bazyl]]></dc:creator>
            <pubDate>Tue, 23 Apr 2019 22:08:39 GMT</pubDate>
            <atom:updated>2019-04-23T22:08:39.016Z</atom:updated>
            <content:encoded><![CDATA[<p>Lately I’ve been doing some spring cleaning of my computer and uncovered a few gems that were sitting around for a long time. A demo I wrote for the Sheets API a few years back was one of my favorite little hacks that was never released as an API sample. I thought it was time to revisit it.</p><p>This original demo was simple — it treated a sheet as a canvas for drawing images, with each cell as a pixel. While not so useful in the real world, it produced some cute results and was useful for testing out the API. It just so happened that drawing images with the API hit on a lot of features — bulk setting cell values, formatting, resizing sheets, etc. But as fun as it was to draw static images, it wasn’t enough.</p><p>I wanted movies. Well, at least some animated GIFs!</p><p>So after dusting things off, I took a stab at animated gifs and learned a few things along the way.</p><h3>I =CHOOSE poorly</h3><p>When I first thought about how to represent animations in cells, I was (overly, in hindsight) concerned with API quota and how much data I was sending. I wondered if there was a way to encode <strong>all</strong> the frames of the GIF in the sheet to minimize updates during animation.</p><p>The =CHOOSE function was just what I was looking for. The function yields a cell value based on a lookup list. In this case, the idea was to store the frame index in 1 cell, then encode the colors for each frame of each pixel in the formula.</p><p>Taking a step back, you can play around with how this works with a simplified version:</p><pre>=CHOOSE($A$1, “|”,”\”, “-”, “/”)</pre><p>If you put that formula in cell A2, then set cell A1 to 1, 2, or 3 you’ll see the value update. Change that value fast enough, and it looks like it’s animated. A small script attached to the sheet helps drive the animation.</p><pre>function animate() {<br>  var ss = SpreadsheetApp.getActiveSheet();<br>  var range = ss.getRange(1, 1);<br>  var maxFrame = 4;<br>  for (var i = 0; i &lt; 100; ++i) {<br>    var frame = (i % maxFrame) + 1;<br>    range.setValue(frame);<br>    SpreadsheetApp.flush();<br>    Utilities.sleep(100);<br>  }<br>}</pre><p>Run the script and voila! Not an animated GIF, but a proof of concept.</p><p>For images we need colors, not text. Enter conditional formatting. You can try it for yourself by setting up some conditional formatting rules for the 4 values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*_PePvTyThcFLr9IeEranOg.png" /></figure><p>Run the script again and now the cell color changes for each frame.</p><p>Now we just need to go from 1 pixel to lots of pixels!</p><p>Encoding an image like this by hand would be tedious, but with the Sheets API, it’s not so bad. There’s a small Node.js script I created at <a href="https://github.com/sqrrrl/animated-sheet/formula.js">https://github.com/sqrrrl/animated-sheet/formula.js</a> that does this work for us. It reads a GIF and for each pixel, encodes the colors for each frame. It also does some resizing of the sheet and cells to make things look a little nicer.</p><p>The resulting sheet looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d3XjuiMbahz9BCBy" /><figcaption>See the <a href="https://tenor.com/view/jumping-rainbow-sheep-rainbow-happy-happy-jump-gif-11755929">original image</a> here</figcaption></figure><p>Each pixel the decimal value of the cell color (in hex, 0xRRGGBB) for the corresponding frame.</p><pre>=CHOOSE($A$1, 16380939, 16380939, 16378891, 16313354, 11859516, 11722536, 11722536, 7863319, 3669396, 6091876, 8977160, 8977160, 10025223)</pre><p>It also creates a conditional formatting rule for each possible color in the image that matches on the color value.</p><p>Here’s where things started heading the wrong way. Each update to the frame index took about 15 seconds to recalculate and render the sheet. While it <strong>technically</strong> worked, it was absurdly slow and not the result I was looking for.</p><p>As it turns out, too many conditional formatting rules make things slow.</p><p><em>Very</em> <em>slow</em>.</p><p>The particular GIF I used had over 500 colors across all the frames, resulting in over 500 conditional formatting rules. Just a wee bit too many for this to work.</p><p>Quantizing the image to reduce the color palette helped. After a little experimentation, 16 colors turned out to be a good balance between aesthetics and performance. Still janky as hell, but as close to good as I was going to get with this approach.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FXLqsg1Vbrw8%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXLqsg1Vbrw8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FXLqsg1Vbrw8%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b82be73aab13cd2a824b4820901bbe8/href">https://medium.com/media/7b82be73aab13cd2a824b4820901bbe8/href</a></iframe><h3>Simple is better</h3><p>As fun as it was getting the GIF to work, I certainly wasn’t ready to get back to my “real” work. So I decided that v2 should follow an approach I originally thought about and discarded — let’s just rewrite the image in full for each frame via the API.</p><p>You can find this version in <a href="https://github.com/sqrrrl/animated-sheet/frames.js">https://github.com/sqrrrl/animated-sheet/frames.js</a>. It’s mostly the same as previous version, but instead of using Apps Script to drive the animation, it’s handled completely in the script and the image is updated via the API for each frame.</p><p>This turns out to be much simpler, doesn’t require quantizing, <strong>and</strong> animates much more smoothly. It’s still janky, but a notable improvement over v1. And certainly good enough to call it quits on this little venture and get back to more serious (ha!) pursuits.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FMVGxiEsbVDk%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DMVGxiEsbVDk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FMVGxiEsbVDk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/772e7ad5f5380d3552a804587603669c/href">https://medium.com/media/772e7ad5f5380d3552a804587603669c/href</a></iframe><h3>Real world implications</h3><p>As effective as this experiment was at wasting time, it wasn’t without value. As mentioned earlier, the original version was a useful exercise for learning the Sheets API and trying out different features.</p><p>Attempting to do animations revealed the performance implications of conditional formatting rules. It turns out that approaching just a dozen or so rules can dramatically slow down recalculations on a moderately complex sheet. Hopefully the Sheets team will continue to make improvements here. (Don’t worry — I already filed the bug.)</p><p>More so, there are countless real world cases that require pushing data to sheets on a frequent basis. What were pixels for me may be sales data, sensor readings, or whatever data you need to keep up-to-date in your sheets.</p><p>And lastly, it was a much needed reminder of the KISS principle. 😙</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86c57597a478" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>