Creating a script to post to Facebook

Hi,

I’ve written a script to post to Facebook which links to four different shortcuts in the Shortcuts app, the one chosen depending on which option is selected by the user. I created four separate shortcuts to accommodate the vagaries of the Shortcuts app (e.g. there is no action to convert a video type) and the Post on Facebook action (e.g. it’s not possible to do inline tagging or add captions to media). Although the script seems to be functioning well, if the Facebook action is called from the share sheet, but is then cancelled, the Drafts app crashes.

https://www.icloud.com/shortcuts/5b395032b78c4c398624aab13315cb15
https://www.icloud.com/shortcuts/19868122b4c9424c9567e5f887a0edaa
https://www.icloud.com/shortcuts/165ea24526834890b812c07042ee7549
https://www.icloud.com/shortcuts/3ec3bc18478b42e889de27b9f3268a24


var text = "false";

(() => {

let cb = CallbackURL.create();
cb.baseURL = "shortcuts://x-callback-url/run-shortcut";

let p = Prompt.create();
var options = ["Captions", "Inline tagging", "Photos (no videos)", "Videos [with photos]"];
var selectedOptions = [""];

p.addSelect("s", "Will your post contain any of the following elements?", options, selectedOptions, true);

p.addButton("OK");

if (!p.show()) {
      context.cancel();
      return;}
else {
if (p.fieldValues['s'] == 'Photos (no videos)');
 cb.addParameter("name", "Post to Facebook (1)");
if (p.fieldValues['s'] == 'Captions'||'Inline tagging'&&'Photos (no videos)');
 cb.addParameter("name", "Post to Facebook (2)");
if (p.fieldValues['s'] == 'Videos [with photos]');
 cb.addParameter("name", "Post to Facebook (3)");
if (p.fieldValues['s'] == 'Captions'||'Inline tagging'&&'Videos [with photos]');
 cb.addParameter("name", "Post to Facebook (4)");
if (p.fieldValues['s'] == ''){
text = "true";}
 
 let success = false;
  if (text == "true"){
    success = Share.shareAsText(draft.processTemplate("[[draft]]"));
  } else {
    success = app.openURL(cb.url);
  }
  return true;
      }
if (success) {
    console.log("Posted to Facebook");
  } else {
    console.log(cb.status);
    if (cb.status == "cancel") {
      context.cancel();
    } else {
      context.fail();
    }
  }
})()

The script is preceded by an action step that copies the contents of the draft to the clipboard.

Any thoughts on this issue, or on the script/shortcuts in general, are most welcome.

Thanks,

Martin