Shortcuts for iPhone and iPad

Using Modzy within an iPhone, iPad or MacOS shortcut is simple

Short tutorial on building a Sentiment Analysis Shortcut.

Intro to Shortcuts on iPhone and iPad

What’s a shortcut?

A shortcut provides a simple way to add features or actions within apps or by asking Siri. Shortcuts can automate a wide variety of things—in example, analyzing text for sentiment.

Build a Modzy Shortcut

  1. In My Shortcuts in the Shortcuts app on iPhone or iPad, tap + in the upper-right corner. An empty shortcut called New Shortcut appears in the shortcut editor.

iPhone shortcut appiPhone shortcut app

  1. Tap [...] Shortcut Name, type the name of your shortcut, and select where you'd like your shortcut to work, then tap Done. For this example turn on Share Sheet and select only Rich Text, Safari pages and Text.

  2. Tap Add Action, search for URL and tap the blue URL action. Type https:/app.modzy.com/api/jobs into the field.

  1. Tap Add Action again and select "Get Contents of URL", then type Show More.
  • Choose POST as the Method

  • Add two new header fields:

    1. Key of Authorization with Text ApiKey <paste your key here>
    2. Key is Content Type with Text application/json
  • The Request Body should be JSON. Now add two new fields:

    1. Add a Dictionary field with Key model. Tap the '0 items' and add a Text item with key identifier and Text of ed542963de, then a key 'version' and a Text of 1.0.1 This is our sentiment analysis model.
    2. Add another Dictionary field with key input Tap the '0 items' and add a Text with key type and Text text, then add another Dictionary field with key sources and tap the 0 items to add another Dictionary field of key my-text and a text item with key input.txt and the Text you can click the Shortcut Input variable.
    3. Click Done until you are back in the main shortcut editing screen. You should have a Request body with fields model and input with 2 items each.
  1. This action will call a Modzy model with the payload of the shortcut input!
  1. Modzy is asynchronous so now we need to retrieve the results of the job. When creating the job, Modzy will return a job identifier we can use to retrieve the results. To get this jobId, tap + and select Get Item from list. This should autofill to Get First Item from Contents of URL.

  2. Tap + and select Get Dictionary Value. Tap key and type jobIdentifier

  3. Tap + and select the blue URL. Edit this to include https://app.modzy.com/api/results/ and then tap the Dictionary Value variable.

  1. This is the location our results are stored. To retrieve the results, add a Get Contents of URL action, this time leave the method as GET but enter the Authorization and Content type as before.
  1. This will retrieve the results of the analysis job, which we must now parse by walking through the JSON object tree.

  2. Add a Get Dictionary Value action, tap key and type results

  3. Add a Get Dictionary Value action, tap key and type my-text

  4. Add a Get Dictionary Value action, tap key and type results.json

  5. Add a Get Dictionary Value action, tap key and type data

  6. Add a Get Dictionary Value action, tap key and type result

  7. Add a Get Dictionary Value action, tap key and type classPredictions

  8. Finally, we are at our results!

  1. From here, let's just display an alert with the results and not parse them further. Add a Show Alert action with the Dictionary Value from the previous step, and the Shortcut Input as the Title.
  1. That's all! It was a lot of steps to parse through that JSON object, but that is just how Shortcuts works.
  2. Let's try it out: go find some text, select it, click Share... in the popup menu, then scroll down until you see your Shortcut in the actions menu.

Did this page help you?