Skip to content

Commit 7e82589

Browse files
gotohumanTillSimon
andauthored
gotoHuman example (#41)
* gotoHuman example * readme * Remove openai-integration * gotoHuman ~0.2.4 --------- Co-authored-by: Till Simon <[email protected]>
1 parent 3875715 commit 7e82589

34 files changed

+3649
-0
lines changed

examples/gotohuman/.env.example

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
OPENAI_API_KEY=
2+
GOTOHUMAN_API_KEY=
3+
GOTOHUMAN_FORM_ID=
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import express, { Request, Response } from 'express';
2+
import { client } from "./src/client";
3+
import { HumanResponseEvent } from './src/events';
4+
5+
const app = express();
6+
app.use(express.json());
7+
const port = process.env.PORT || 4000;
8+
9+
app.post('/', async (req: Request, res: Response) => {
10+
console.log(`Received webhook from gotoHuman`, req.body)
11+
12+
try {
13+
// Our gotoHuman review form also contains a buttonSelect with the ID 'publishDecision', value: publish|discard
14+
const workflowResponse = await client.sendWorkflowEvent({
15+
event: {
16+
name: HumanResponseEvent.name,
17+
input: {
18+
linkedInPost: req.body?.responseValues?.linkedInPost?.value || "",
19+
publishDecision: req.body?.responseValues?.publishDecision?.value || ""
20+
},
21+
},
22+
workflow: {
23+
workflowId: req.body?.meta?.restackWorkflowId,
24+
runId: req.body?.meta?.restackRunId,
25+
},
26+
});
27+
console.log(`Sent event to workflow. Returned ${workflowResponse}`)
28+
29+
res.status(200).json({msg: 'Processed human feedback ' + workflowResponse})
30+
} catch(e) {
31+
console.error("Sending event to workflow failed!", e)
32+
res.status(500).json({error: `Could not process webhook!`})
33+
}
34+
});
35+
36+
app.listen(port, () => {
37+
console.log(`Server running at http://localhost:${port}`);
38+
});

0 commit comments

Comments
 (0)