Skip to content

Commit 0e7cdc4

Browse files
committed
streamlabs init
1 parent cc775a1 commit 0e7cdc4

File tree

7 files changed

+583
-3
lines changed

7 files changed

+583
-3
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import streamlabs from "../../streamlabs.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "streamlabs-send-alert",
6+
name: "Send Alert",
7+
description: "Sends an alert to the stream overlay with a custom message, image, and sound. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
streamlabs: {
12+
type: "app",
13+
app: "streamlabs",
14+
},
15+
alertMessageContent: {
16+
propDefinition: [
17+
streamlabs,
18+
"alertMessageContent",
19+
],
20+
},
21+
alertImageUrl: {
22+
propDefinition: [
23+
streamlabs,
24+
"alertImageUrl",
25+
],
26+
optional: true,
27+
},
28+
alertSoundUrl: {
29+
propDefinition: [
30+
streamlabs,
31+
"alertSoundUrl",
32+
],
33+
optional: true,
34+
},
35+
},
36+
async run({ $ }) {
37+
const response = await this.streamlabs.sendAlert({
38+
alertMessageContent: this.alertMessageContent,
39+
alertImageUrl: this.alertImageUrl,
40+
alertSoundUrl: this.alertSoundUrl,
41+
});
42+
$.export("$summary", `Alert sent with message: ${this.alertMessageContent}`);
43+
return response;
44+
},
45+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import streamlabs from "../../streamlabs.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "streamlabs-start-stream",
6+
name: "Start Live Stream",
7+
description: "Starts a live stream. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
streamlabs,
12+
streamTitle: {
13+
propDefinition: [
14+
streamlabs,
15+
"streamTitle",
16+
],
17+
},
18+
gameCategory: {
19+
propDefinition: [
20+
streamlabs,
21+
"gameCategory",
22+
],
23+
optional: true,
24+
},
25+
},
26+
async run({ $ }) {
27+
const response = await this.streamlabs.startLiveStream({
28+
streamTitle: this.streamTitle,
29+
gameCategory: this.gameCategory,
30+
});
31+
$.export("$summary", `Started live stream with title "${this.streamTitle}"`);
32+
return response;
33+
},
34+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import streamlabs from "../../streamlabs.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "streamlabs-update-overlay",
6+
name: "Update Stream Overlay",
7+
description: "Updates a specific stream overlay with new values, such as text, images, or stats. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
streamlabs,
12+
overlayId: {
13+
propDefinition: [
14+
streamlabs,
15+
"overlayId",
16+
],
17+
},
18+
contentUpdates: {
19+
propDefinition: [
20+
streamlabs,
21+
"contentUpdates",
22+
],
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.streamlabs.updateOverlay({
27+
overlayId: this.overlayId,
28+
contentUpdates: this.contentUpdates,
29+
});
30+
$.export("$summary", `Updated overlay ${this.overlayId} successfully`);
31+
return response;
32+
},
33+
};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import streamlabs from "../../streamlabs.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "streamlabs-new-follower-instant",
6+
name: "New Follower",
7+
description: "Emit a new event when a viewer follows the streamer's channel. [See the documentation]($docsLink)",
8+
version: "0.0.{{ts}}",
9+
type: "source",
10+
dedupe: "unique",
11+
props: {
12+
streamlabs: {
13+
type: "app",
14+
app: "streamlabs",
15+
},
16+
http: {
17+
type: "$.interface.http",
18+
customResponse: false,
19+
},
20+
db: "$.service.db",
21+
},
22+
hooks: {
23+
async deploy() {
24+
const followEvents = await this.streamlabs.emitFollowEvent({
25+
paginate: true,
26+
max: 50,
27+
});
28+
for (const follow of followEvents.reverse()) {
29+
this.$emit(follow, {
30+
id: follow.id || follow.ts,
31+
summary: `New follower: ${follow.username}`,
32+
ts: follow.timestamp
33+
? Date.parse(follow.timestamp)
34+
: Date.now(),
35+
});
36+
}
37+
},
38+
async activate() {
39+
const webhook = await this.streamlabs._makeRequest({
40+
method: "POST",
41+
path: "/webhooks",
42+
data: {
43+
event: "follow_event",
44+
callback_url: this.http.url,
45+
},
46+
});
47+
const webhookId = webhook.id;
48+
if (webhookId) {
49+
await this.db.set("webhookId", webhookId);
50+
}
51+
},
52+
async deactivate() {
53+
const webhookId = await this.db.get("webhookId");
54+
if (webhookId) {
55+
await this.streamlabs._makeRequest({
56+
method: "DELETE",
57+
path: `/webhooks/${webhookId}`,
58+
});
59+
await this.db.delete("webhookId");
60+
}
61+
},
62+
},
63+
async run(event) {
64+
const followEvent = event.data;
65+
this.$emit(followEvent, {
66+
id: followEvent.id || followEvent.ts,
67+
summary: `New follower: ${followEvent.username}`,
68+
ts: followEvent.timestamp
69+
? Date.parse(followEvent.timestamp)
70+
: Date.now(),
71+
});
72+
},
73+
};
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import streamlabs from "../../streamlabs.app.mjs";
2+
import crypto from "crypto";
3+
import { axios } from "@pipedream/platform";
4+
5+
export default {
6+
key: "streamlabs-new-subscriber-instant",
7+
name: "New Subscriber (Instant)",
8+
description: "Emit new event when a viewer subscribes to the streamer's channel. [See the documentation]()",
9+
version: "0.0.{{ts}}",
10+
type: "source",
11+
dedupe: "unique",
12+
props: {
13+
streamlabs: {
14+
type: "app",
15+
app: "streamlabs",
16+
},
17+
http: {
18+
type: "$.interface.http",
19+
customResponse: true,
20+
},
21+
db: "$.service.db",
22+
subscriptionPlanTier: {
23+
propDefinition: [
24+
"streamlabs",
25+
"subscriptionPlanTier",
26+
],
27+
optional: true,
28+
},
29+
},
30+
hooks: {
31+
async deploy() {
32+
const params = this.subscriptionPlanTier
33+
? {
34+
tier: this.subscriptionPlanTier,
35+
}
36+
: {};
37+
const subscriptions = await this.streamlabs.paginate(this.streamlabs.emitSubscribeEvent, params);
38+
const recentSubscriptions = subscriptions.slice(-50);
39+
for (const subscription of recentSubscriptions) {
40+
this.$emit(subscription, {
41+
id: subscription.id || subscription.ts,
42+
summary: `New subscription from ${subscription.username}`,
43+
ts: new Date(subscription.created_at).getTime(),
44+
});
45+
}
46+
},
47+
async activate() {
48+
const callbackUrl = this.http.endpoint;
49+
const data = {
50+
url: callbackUrl,
51+
event: "subscribe",
52+
...(this.subscriptionPlanTier
53+
? {
54+
tier: this.subscriptionPlanTier,
55+
}
56+
: {}),
57+
};
58+
const webhook = await this.streamlabs._makeRequest({
59+
method: "POST",
60+
path: "/webhooks",
61+
data,
62+
});
63+
await this.db.set("webhookId", webhook.id);
64+
},
65+
async deactivate() {
66+
const webhookId = await this.db.get("webhookId");
67+
if (webhookId) {
68+
await this.streamlabs._makeRequest({
69+
method: "DELETE",
70+
path: `/webhooks/${webhookId}`,
71+
});
72+
await this.db.set("webhookId", null);
73+
}
74+
},
75+
},
76+
async run(event) {
77+
const rawBody = event.rawBody;
78+
const signature = event.headers["X-Streamlabs-Signature"];
79+
80+
const secret = this.streamlabs.$auth.secret;
81+
const computedSignature = crypto.createHmac("sha256", secret).update(rawBody)
82+
.digest("hex");
83+
84+
if (computedSignature !== signature) {
85+
this.http.respond({
86+
status: 401,
87+
body: "Unauthorized",
88+
});
89+
return;
90+
}
91+
92+
const subscription = event.body;
93+
94+
if (this.subscriptionPlanTier && subscription.tier !== this.subscriptionPlanTier) {
95+
this.http.respond({
96+
status: 200,
97+
body: "Ignored",
98+
});
99+
return;
100+
}
101+
102+
this.$emit(subscription, {
103+
id: subscription.id || subscription.ts,
104+
summary: `New subscription from ${subscription.username}`,
105+
ts: Date.parse(subscription.created_at) || Date.now(),
106+
});
107+
108+
this.http.respond({
109+
status: 200,
110+
body: "OK",
111+
});
112+
},
113+
};

0 commit comments

Comments
 (0)