Questscript Completion Actions

Questscript completion actions are useful for scenarios when you need more flexibility or want to integrate with a service not yet supported by Questmate or Zapier.

Completion Action Examples

Send Messages

Send a Slack message
Send a Discord message
Send an SMS message
Send an Email

Export data

Export data to Airtable
Export data to Google Sheets
Export data to Notion
Export data to Zoho Creator Form Record

How it works

  1. When editing a Quest, create a new Completion Action and change the type to "QuestScript" using the gear icon
  2. Enter your own custom Javascript code into the provided text box
  3. When a Quest run is submitted successfully your QuestScript will execute along with any other Completion Actions provided

Questscript Context

QuestScript code is executed within a limited Javascript environment.

Although limited, Questmate provides the following important functionality:

  • fetch is provided and available for use. See using the Fetch API
  • Allows scripts to make calls to other services on the internet (useful to call your own server to emulate webhook functionality)
  • A questmate client is provided to make calls to the Questmate API (further documentation to come)
  • The quest object contains a representation of the Quest, including data entered into items

Here is an example of a quest object:


{
  "name": "A Sample Quest",
  "items": [
    {
      "id": "ea120f86-a713-4023-a05a-4e1898ff7c36:aa9c841c-6370-41db-b7dc-7e21af42c056",
      "data": {
        "checked": true
      },
      "name": "Are you a current Questmate customer?",
      "type": "Checkbox",
      "referenceSlug": "is_customer"
    },
    {
      "id": "ea120f86-a713-4023-a05a-4e1898ff7c36:fc4a405e-091f-4946-acaf-2959bba67597",
      "data": {
        "text": "Jack"
      },
      "name": "Name",
      "type": "Text",
      "referenceSlug": null
    },
    {
      "id": "ea120f86-a713-4023-a05a-4e1898ff7c36:f9ff591f-f7d9-4621-98ff-e702b900e6dc",
      "data": {
        "value": "2022-09-08T23:00:00Z"
      },
      "name": "Desired Appointment Time",
      "type": "DateTime",
      "referenceSlug": null
    }
  ],
  "instanceId": "2083556b-c6cc-47ff-9e71-35024f884eab",
  "prototypeId": "ea120f86-a713-4023-a05a-4e1898ff7c36"
}

Helpers

We wrote these little helper methods to make it easier to do things like creating a new sub quest and adding assignees to them and setting due dates.

const reviewQuestItem = quest.parent.getItem('Booking request review')
const reviewQuestRun = reviewQuestItem.subquestRun;
const reviewQuestInstance = reviewQuestItem.subquests[0];

await reviewQuestRun.addAssignees('jack+test1@questmate.com');
await reviewQuestRun.setDueDate('next wednesday at 4pm');
await quest.copyMatchingItemsTo(reviewQuestInstance);

// Rename Quest Run
await quest.setName("Visitor: Steven Smith");

Submit Parent Quest

If you have a quest that contains just sub quests inside (no other item types like text fields or multi-selects etc), then this one-liner makes it so you can submit the full quest when you complete the final sub quest. You don’t have to go back up a level to submit it.

// Useful if all items in the parent Quest are Subquests.
// Eliminates the need to submit the parent after submitting the last Subquest.
await quest.parent.submit()

Redirect to URL

You can redirect your users on completion of a Quest to any URL as shown below where we Show a button with the text “Reset Form”. It will countdown from 5 seconds and then automatically redirect users to xkcd.com afterwards.

return {
  actions: [
    {
      type: 'navigate',
      linkText: 'Reset Form',
      to: 'https://www.xkcd.com',
      autoRedirectDelay: 5
    }
  ]
}

When making public Quests, it is often useful to be able to loop to the start of a new Quest on completion of a Quest. To do this, you can redirect to the public quest route, creating a new blank Quest to fill out, using the following example. Feel free to adjust the autoRedirectDelay or linkText to suit your needs.

const publicId = await quest.getPublicId();
return {
  actions: [
    {
      type: 'navigate',
      autoRedirectDelay: 5,
      linkText: 'Reset Form',
      to: {
        screen: "PublicAssignment",
        params: { id: publicId },
        type: 'REPLACE',
      }
    }
  ]
}
📌
Notes:
  • autoRedirectDelay is optional and will not automatically redirect users if not present.
  • type: 'REPLACE' is also optional, if not specified the user will be able to go back to the previous Quest after navigating to the redirected location.

Copyright © Questmate Pty Ltd.