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
httpsaddress. Picked sends requests only to publichttpsaddresses.
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 tsxThe 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:
endpointis the address of the app server. Picked sends its requests below this address.- The
app-homeslot is a page that the dashboard shows in the project. score_leadis a workflow tool. Itseffectisread, 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:
createAppHandlerchecks that Picked signed each request. Then it sends the request toonInstallor to thescore_leadtool.fallbackserves the page, and the script/app-kit/frame.jsthat the page imports.- The page calls
connectto get its context from the dashboard. Then it callsautoResize, 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 generateA 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.comUse the line from step 4 for PICKED_APP_PRIVATE_KEY. Then start the server:
npx tsx src/server.tsListening 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 loginLogged 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 acmeDeployed 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
- In the dashboard, open your project.
- In the project switcher, choose Apps.
- Choose the tab Available.
- Find Lead Score. It has the badge Dev.
- 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
- Open your workflow.
- Choose Add node.
- Choose Add tool.
- Choose Lead Score: Score lead.
- Set
emailtoada@acme.com. - Set
companytoAcme. - Open the Test tab.
- Enter the trigger input that the form asks for.
- 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
- About apps — what an app is, and how versions and installations work.
- How to work on an app from your machine — change the app and send the change to your installation.
- How to test an app — test the handler without a Picked API.
- How to deploy an app — deploy a release version from a public server.
- App manifest — every field of the
appsection. @picked/app-kit— every function of the package.
