Skip to content
LogoLogo

Build and install your first app

In this tutorial we build a small Picked app, install it on a project, and run its workflow tool. The app is named Lead Score. It gives a lead a score from its email address and its company.

At the end you have an app server on your machine. The dashboard shows its page, and a workflow test run gets a score from it.

Before you start

  • A Picked organization in which you are an Owner.
  • A project in that organization, with a workflow.
  • Node 24 or later.
  • A tool that forwards a port on your machine to a public https address. Picked sends requests only to public https addresses.

1. Make the app directory

Make a directory for the app. Install @picked/app-kit, @picked/config, @picked/cli and tsx in it:

mkdir lead-score
cd lead-score
npm init -y
npm pkg set type=module
npm install @picked/app-kit @picked/config
npm install --save-dev @picked/cli tsx

The directory now holds a package.json file and a node_modules directory.

2. Write the manifest

The manifest tells Picked what the app adds to a project. The manifest is the app section of the picked.config.ts file. Make the file picked.config.ts in the lead-score directory:

import { defineConfig } from '@picked/config/define'
 
const endpoint = 'http://localhost:4103'
 
export default defineConfig({
  app: {
    handle: 'lead-score',
    name: 'Lead Score',
    description: 'Gives a lead a score from its email address and its company.',
    endpoint,
    slots: [{ location: 'app-home', url: `${endpoint}/`, title: 'Lead Score', height: 200 }],
    workflowTools: [
      {
        name: 'score_lead',
        label: 'Score lead',
        description: 'Gives a lead a score from 0 to 100, and names its tier.',
        effect: 'read',
        arguments: {
          email: { label: 'Email', type: 'string', required: true },
          company: { label: 'Company', type: 'string' },
        },
        output: {
          score: { label: 'Score', type: 'number' },
          tier: { label: 'Tier', type: 'string', description: 'hot, warm or cold' },
        },
      },
    ],
  },
})

This manifest declares three things:

  • endpoint is the address of the app server. Picked sends its requests below this address.
  • The app-home slot is a page that the dashboard shows in the project.
  • score_lead is a workflow tool. Its effect is read, so a workflow test run runs it.

The endpoint is a local address for now. In step 7 the CLI changes it to your public address.

3. Write the server

Make the file src/server.ts:

import { createAppHandler, json, page, readAppEnvironment } from '@picked/app-kit/server'
import { frameScript, serve } from '@picked/app-kit/node'
 
const port = '4103'
const { pickedKeys, frameAncestors } = readAppEnvironment(process.env, port)
 
const freeMail = new Set(['gmail.com', 'outlook.com', 'hotmail.com', 'yahoo.com', 'icloud.com'])
 
function scoreLead(email: string, company: string): { score: number; tier: string } {
  const domain = email.split('@')[1]?.toLowerCase() ?? ''
  let score = 20
  if (domain !== '' && !freeMail.has(domain)) score += 40
  if (company.trim() !== '') score += 20
  const tier = score >= 70 ? 'hot' : score >= 40 ? 'warm' : 'cold'
  return { score, tier }
}
 
const homePage = `<!doctype html>
<html lang="en">
<head><meta charset="utf-8" /></head>
<body style="font: 14px system-ui, sans-serif">
<p id="status">Connecting to Picked…</p>
<script type="module">
  import { connect, autoResize } from '/app-kit/frame.js'
  const context = await connect()
  document.getElementById('status').textContent =
    'Lead Score version ' + context.appVersion + ' is installed in ' + context.organizationSlug + '.'
  autoResize()
</script>
</body>
</html>`
 
const handler = createAppHandler({
  pickedKeys,
  onInstall: (event) => {
    console.log(`Installed on project ${event.projectId}`)
  },
  tools: {
    score_lead(call) {
      const email = typeof call.arguments.email === 'string' ? call.arguments.email : ''
      const company = typeof call.arguments.company === 'string' ? call.arguments.company : ''
      return Promise.resolve(scoreLead(email, company))
    },
  },
  fallback(request) {
    const { pathname } = new URL(request.url)
    if (pathname === '/') return page(homePage, { frameAncestors })
    if (pathname === '/app-kit/frame.js') return frameScript()
    return json({ error: 'not_found' }, 404)
  },
})
 
serve(handler, Number(port))

The server has three parts:

  • createAppHandler checks that Picked signed each request. Then it sends the request to onInstall or to the score_lead tool.
  • fallback serves the page, and the script /app-kit/frame.js that the page imports.
  • The page calls connect to get its context from the dashboard. Then it calls autoResize, which keeps the height of the page in the dashboard equal to its content.

4. Make the keys of the app

The app server and the CLI need the private key of the app. Make a private key and its public key:

npx picked app keys generate
A new app key pair. Keep the private key secret; it is printed once:

PICKED_APP_PRIVATE_KEY=MC4CAQAwBQYDK2VwBCIEI…

Public key: 3fJ0b…
Key id:     Qm9yZ2…

Set PICKED_APP_PRIVATE_KEY on the app server and where you run `picked app deploy`,
which registers the public key with the app.

Copy the PICKED_APP_PRIVATE_KEY=… line to a safe place. The CLI shows it one time only.

5. Make the port public

Open a second shell. Forward port 4103 to a public https address with your tool.

The tool shows a public https address, such as https://lead-score.tunnel.example. Copy that address. In the next steps, put it where you see https://lead-score.tunnel.example.

6. Start the server

Go back to the first shell. Set the four values that the server reads:

export PICKED_APP_PRIVATE_KEY='MC4CAQAwBQYDK2VwBCIEI…'
export PICKED_API_URL=https://api.picked.app
export APP_PUBLIC_URL=https://lead-score.tunnel.example
export PICKED_DASHBOARD_ORIGINS=https://dashboard.picked.app,https://*.picked.app,https://dashboard.convincely.com

Use the line from step 4 for PICKED_APP_PRIVATE_KEY. Then start the server:

npx tsx src/server.ts
Listening on http://localhost:4103

Keep this shell open. The server writes one line for each request that it gets.

7. Deploy a dev version

Open one more shell in the lead-score directory. Set the private key, and sign in the CLI:

export PICKED_APP_PRIVATE_KEY='MC4CAQAwBQYDK2VwBCIEI…'
npx picked login
Logged in as you@example.com (https://api.picked.app)

Deploy the manifest as a dev version that uses your public address. Put the slug of your organization in place of acme:

npx picked app dev --endpoint https://lead-score.tunnel.example --org acme
Deployed Lead Score (lead-score) dev version 1 [app_…]

The first deploy makes the app in your organization. The CLI also registers the public key of the app. The endpoint and the slot address now start with your public address.

8. Install the app

  1. In the dashboard, open your project.
  2. In the project switcher, choose Apps.
  3. Choose the tab Available.
  4. Find Lead Score. It has the badge Dev.
  5. Choose Install.

The window Install Lead Score? opens. It shows "This app asks for no access to your data." because the manifest declares no scopes. Choose Install.

Lead Score moves to the tab Installed. Below its name, the line shows Version 1 · 1 slot · Workflow tools: app.lead-score.score_lead. The app asks for no scopes, so it has no access line. The server shell shows the installation:

Installed on project 7d1c…
POST /lifecycle 200

9. Open the page

On the line of Lead Score, choose Open.

The dashboard opens the page of the app in the project. The page shows:

Lead Score version 1 is installed in acme.

The server shell shows GET / 200 and GET /app-kit/frame.js 200.

10. Run the tool in a workflow

  1. Open your workflow.
  2. Choose Add node.
  3. Choose Add tool.
  4. Choose Lead Score: Score lead.
  5. Set email to ada@acme.com.
  6. Set company to Acme.
  7. Open the Test tab.
  8. Enter the trigger input that the form asks for.
  9. Choose Run test.

The result shows the tool node with the status Succeeded. Its Output is:

{ "score": 80, "tier": "hot" }

The server shell shows POST /tools/score_lead 200.

What you built

You built an app with a page and a workflow tool. You deployed it from your machine as a dev version, and installed it on a project. The dashboard shows its page, and a workflow gets a score from your server.

The app server keeps no data. Picked signs each request that it sends. The server makes sure that a public key of Picked signed it.

Where to go next