Android share target - alternative implementation

I want to add SilverBullet as a “share” target on Android. This would allow me to send it pages I’m looking at, notes from chats, and others. I’ve requested a native PWA implementation in #1090, but in the meantime I found an alternative.

https://http-shortcuts.rmy.ch/ is an Android app that lets you set up a custom share target which sends an HTTP request. My config:

  • Basic request is PUT to https://my.sb.instance/Inbox/{dateSlashTime}.md
    • dateSlashTime is a global variable (you can define it from the “basic request” dialog) of type Timestamp, with format yyyy-MM-dd/HH-mm-ss.
    • Altogether, this makes it compatible with the built-in “quick note” syntax.
  • Request headers is X-Sync-Mode set to true, a la https://silverbullet.md/HTTP%20API
  • Request body has Content-Type set to text/markdown, and request body set to {quickNoteContents}
    • quickNoteContents is a Text inputglobal variable, with Multiline enabled,Allow Receiving Value from Share Dialogueenabled, andData to Receive from Sharingset toText only`.
  • Authentication is set to Bearer Authentication, configured with SB_AUTH_TOKEN a la https://silverbullet.md/Install/Configuration#Authentication
  • Response Handling is set to display a Toast Popup

And that’s basically it! Now I can either go to HTTP shortcut directly from the app, from its shortcut menu (holding the app icon on the homescreen), or I can use the Share button in app to send a quick note to silverbullet.

To make these useful, I also have a bit of space lua; inbox.notes() shows everything from the inbox (I have this on my index page), and because I often just delete these notes directly from my mobile, I also automatically show a Page: Delete bottom on them.

function inbox.notes()
  local res = template.each(query[[
    from index.tag "page"
    where string.startsWith(name, "Inbox/")
  ]], template.new[==[
**[[${name}|${string.sub(name,7)}]]** - ![[${name}]]
]==])
  if some(res) then
    return [==[# Inbox notes
]==] .. string.trimEnd(res)
  else
    return ""
  end
end

local inboxBottomTemplate = template.new[==[This is an inbox page
]==]


local function inboxBottomWidget()
  if not string.startsWith(editor.getCurrentPage(), "Inbox/") then
    return nil
  end
  return widgets.commandButton("Delete this note", "Page: Delete")
end
  
event.listen {
  name = "hooks:renderBottomWidgets",
  run = inboxBottomWidget
}
4 Likes

Thank you for this howto. This is one feature that I have been missing or a while although I did see the HTTP Shortcuts app, I never got around to trying it out. I have now set it up using your pointers and works great. Thanks again.

I really love this idea.

How do you get the command button to render?
For me using this code results in the following output:
image

Not sure why that doesn’t work for you. Try simply doing ${widgets.commandButton("Page: Delete")}, that should work on silverbullet v2.

Hmmm. Just adding the command button works for me.
Weird.