Skip to content

Commit ab15381

Browse files
committed
breathe init
1 parent e5390d0 commit ab15381

File tree

8 files changed

+684
-4
lines changed

8 files changed

+684
-4
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import breathe from "../../breathe.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "breathe-log-breathing-activity",
6+
name: "Log Breathing Activity",
7+
description: "Log manual breathing activity data for a user, including duration, type of activity, and optional notes. [See the documentation](https://developer.breathehr.com/documentation/introduction)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
breathe,
12+
typeOfActivity: {
13+
propDefinition: [
14+
breathe,
15+
"typeOfActivity",
16+
],
17+
},
18+
duration: {
19+
propDefinition: [
20+
breathe,
21+
"duration",
22+
],
23+
},
24+
notes: {
25+
propDefinition: [
26+
breathe,
27+
"notes",
28+
],
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = await this.breathe.logActivity({
33+
typeOfActivity: this.typeOfActivity,
34+
duration: this.duration,
35+
notes: this.notes,
36+
});
37+
$.export(
38+
"$summary",
39+
`Logged breathing activity of type ${this.typeOfActivity} with duration ${this.duration} minutes${this.notes
40+
? ` and notes: ${this.notes}`
41+
: ""}.`,
42+
);
43+
return response;
44+
},
45+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import breathe from "../../breathe.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "breathe-send-relaxation-reminder",
6+
name: "Send Relaxation Reminder",
7+
description: "Sends a personalized reminder to begin a relaxation or breathing session. [See the documentation](https://developer.breathehr.com/documentation/introduction)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
breathe,
12+
reminderMessage: {
13+
propDefinition: [
14+
breathe,
15+
"reminderMessage",
16+
],
17+
},
18+
deliveryTime: {
19+
propDefinition: [
20+
breathe,
21+
"deliveryTime",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.breathe.sendReminder({
27+
reminderMessage: this.reminderMessage,
28+
deliveryTime: this.deliveryTime,
29+
});
30+
$.export("$summary", `Sent relaxation reminder scheduled at ${this.deliveryTime}`);
31+
return response;
32+
},
33+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import breathe from "../../breathe.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "breathe-start-guided-session",
6+
name: "Start Guided Breathing Session",
7+
description: "Starts a new guided breathing session for a user. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
breathe,
12+
sessionType: {
13+
propDefinition: [
14+
breathe,
15+
"sessionType",
16+
],
17+
},
18+
duration: {
19+
propDefinition: [
20+
breathe,
21+
"duration",
22+
],
23+
},
24+
intensity: {
25+
propDefinition: [
26+
breathe,
27+
"intensity",
28+
],
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = await this.breathe.startSession({
33+
sessionType: this.sessionType,
34+
duration: this.duration,
35+
intensity: this.intensity,
36+
});
37+
$.export("$summary", `Started guided breathing session with ID ${response.id}`);
38+
return response;
39+
},
40+
};

components/breathe/breathe.app.mjs

Lines changed: 206 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,214 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "breathe",
4-
propDefinitions: {},
6+
version: "0.0.{{ts}}",
7+
propDefinitions: {
8+
sessionType: {
9+
type: "string",
10+
label: "Session Type",
11+
description: "The type of guided breathing session",
12+
optional: true,
13+
async options() {
14+
const sessions = await this.getSessionTypes();
15+
return sessions.map((session) => ({
16+
label: session.name,
17+
value: session.id,
18+
}));
19+
},
20+
},
21+
intensity: {
22+
type: "string",
23+
label: "Intensity",
24+
description: "The intensity level of the breathing session",
25+
optional: true,
26+
async options() {
27+
return [
28+
{
29+
label: "Low",
30+
value: "low",
31+
},
32+
{
33+
label: "Medium",
34+
value: "medium",
35+
},
36+
{
37+
label: "High",
38+
value: "high",
39+
},
40+
];
41+
},
42+
},
43+
milestoneType: {
44+
type: "string",
45+
label: "Milestone Type",
46+
description: "The type of breathing milestone",
47+
optional: true,
48+
async options() {
49+
const milestones = await this.getMilestoneTypes();
50+
return milestones.map((milestone) => ({
51+
label: milestone.name,
52+
value: milestone.id,
53+
}));
54+
},
55+
},
56+
typeOfActivity: {
57+
type: "string",
58+
label: "Activity Type",
59+
description: "The type of breathing activity to log",
60+
async options() {
61+
const activities = await this.getActivityTypes();
62+
return activities.map((activity) => ({
63+
label: activity.name,
64+
value: activity.id,
65+
}));
66+
},
67+
},
68+
duration: {
69+
type: "integer",
70+
label: "Duration",
71+
description: "Duration of the session or activity in minutes",
72+
optional: true,
73+
min: 1,
74+
},
75+
notes: {
76+
type: "string",
77+
label: "Notes",
78+
description: "Optional notes for the breathing activity",
79+
optional: true,
80+
},
81+
reminderMessage: {
82+
type: "string",
83+
label: "Reminder Message",
84+
description: "Personalized message for the reminder",
85+
},
86+
deliveryTime: {
87+
type: "string",
88+
label: "Delivery Time",
89+
description: "Time to send the reminder (ISO 8601 format)",
90+
},
91+
},
592
methods: {
6-
// this.$auth contains connected account data
793
authKeys() {
894
console.log(Object.keys(this.$auth));
995
},
96+
_baseUrl() {
97+
return "https://api.breathehr.com";
98+
},
99+
async _makeRequest(opts = {}) {
100+
const {
101+
$ = this, method = "GET", path = "/", headers = {}, ...otherOpts
102+
} = opts;
103+
return axios($, {
104+
...otherOpts,
105+
method,
106+
url: this._baseUrl() + path,
107+
headers: {
108+
...headers,
109+
Authorization: `Bearer ${this.$auth.api_token}`,
110+
},
111+
});
112+
},
113+
async getSessionTypes(opts = {}) {
114+
return this._makeRequest({
115+
method: "GET",
116+
path: "/sessions/types",
117+
...opts,
118+
});
119+
},
120+
async getMilestoneTypes(opts = {}) {
121+
return this._makeRequest({
122+
method: "GET",
123+
path: "/milestones/types",
124+
...opts,
125+
});
126+
},
127+
async getActivityTypes(opts = {}) {
128+
return this._makeRequest({
129+
method: "GET",
130+
path: "/activities/types",
131+
...opts,
132+
});
133+
},
134+
async startSession({
135+
sessionType, duration, intensity, ...opts
136+
}) {
137+
const data = {
138+
session_type: sessionType,
139+
duration,
140+
intensity,
141+
};
142+
return this._makeRequest({
143+
method: "POST",
144+
path: "/sessions/start",
145+
data,
146+
...opts,
147+
});
148+
},
149+
async logActivity({
150+
typeOfActivity, duration, notes, ...opts
151+
}) {
152+
const data = {
153+
activity_type: typeOfActivity,
154+
duration,
155+
notes,
156+
};
157+
return this._makeRequest({
158+
method: "POST",
159+
path: "/activities/log",
160+
data,
161+
...opts,
162+
});
163+
},
164+
async sendReminder({
165+
reminderMessage, deliveryTime, ...opts
166+
}) {
167+
const data = {
168+
message: reminderMessage,
169+
delivery_time: deliveryTime,
170+
};
171+
return this._makeRequest({
172+
method: "POST",
173+
path: "/reminders/send",
174+
data,
175+
...opts,
176+
});
177+
},
178+
async emitNewSessionEvent(filters = {}) {
179+
// Implementation depends on Pipedream's event emission capabilities
180+
// Example:
181+
// this.$emit({ session: filters });
182+
},
183+
async emitMilestoneReachedEvent(milestoneType = null) {
184+
// Implementation depends on specifics
185+
// Example:
186+
// this.$emit({ milestone: milestoneType });
187+
},
188+
async emitReportGeneratedEvent() {
189+
// Implementation depends on specifics
190+
// Example:
191+
// this.$emit({ report: "new_stress_relaxation_report" });
192+
},
193+
async paginate(fn, ...opts) {
194+
let results = [];
195+
let hasMore = true;
196+
let page = 1;
197+
198+
while (hasMore) {
199+
const response = await fn({
200+
page,
201+
...opts,
202+
});
203+
if (!response || response.length === 0) {
204+
hasMore = false;
205+
} else {
206+
results = results.concat(response);
207+
page += 1;
208+
}
209+
}
210+
211+
return results;
212+
},
10213
},
11-
};
214+
};

components/breathe/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)