1import { createOxinion } from 'oxinion';
2
3const oxinion = createOxinion({ apiKey: process.env.OXINION_API_KEY! });
4
5// 1. Create a geofence trigger
6const { geofence } = await oxinion.geofencing.create({
7 name: "Downtown Store",
8 lat: 43.6532,
9 lng: -79.3832,
10 radius: 200,
11 triggerType: "enter",
12});
13
14// 2. Create a pipeline linked to the geofence
15const { pipeline } = await oxinion.pipeline.create({
16 name: "Welcome campaign",
17 geofenceId: geofence.id,
18 triggerEvent: "enter",
19});
20
21// 3. Add action nodes
22await oxinion.nodes.create({
23 pipelineId: pipeline.id,
24 type: "notify",
25 orderIndex: 0,
26 config: {
27 userId: "{{userId}}",
28 title: "You're near us!",
29 body: "Get 20% off today only.",
30 },
31});
32
33await oxinion.nodes.create({
34 pipelineId: pipeline.id,
35 type: "mail",
36 orderIndex: 1,
37 config: {
38 to: "{{userEmail}}",
39 subject: "Your exclusive offer",
40 html: "<p>Thanks for visiting {{geofenceName}}!</p>",
41 },
42});
43
44// Now oxinion.track() fires the pipeline automatically
45await oxinion.track({ type: "enter", lat: 43.6532, lng: -79.3832, userId: "user_123" });