Skip to content

[Components] habitica #13284 #17012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions components/habitica/.gitignore

This file was deleted.

79 changes: 79 additions & 0 deletions components/habitica/actions/create-challenge/create-challenge.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import app from "../../habitica.app.mjs";

export default {
key: "habitica-create-challenge",
name: "Create Challenge",
description: "Creates a challenge. [See the documentation](https://habitica.com/apidoc/#api-Challenge-CreateChallenge)",
version: "0.0.1",
type: "action",
props: {
app,
type: {
propDefinition: [
app,
"type",
],
},
group: {
propDefinition: [
app,
"group",
(c) => ({
type: c.type,
}),
],
},
name: {
propDefinition: [
app,
"name",
],
},
shortName: {
propDefinition: [
app,
"shortName",
],
},
summary: {
propDefinition: [
app,
"summary",
],
},
description: {
propDefinition: [
app,
"description",
],
},
official: {
propDefinition: [
app,
"official",
],
},
prize: {
propDefinition: [
app,
"prize",
],
},
},
async run({ $ }) {
const response = await this.app.createChallenge({
$,
data: {
group: this.group,
name: this.name,
shortName: this.shortName,
summary: this.summary,
description: this.description,
official: this.official,
prize: this.prize,
},
});
$.export("$summary", "Successfully created challenge with ID: " + response.data._id);
return response;
},
};
26 changes: 26 additions & 0 deletions components/habitica/actions/delete-challenge/delete-challenge.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import app from "../../habitica.app.mjs";

export default {
key: "habitica-delete-challenge",
name: "Delete Challenge",
description: "Delete the challenge with the specified ID. [See the documentation](https://habitica.com/apidoc/#api-Challenge-DeleteChallenge)",
version: "0.0.1",
type: "action",
props: {
app,
challengeId: {
propDefinition: [
app,
"challengeId",
],
},
},
async run({ $ }) {
const response = await this.app.deleteChallenge({
$,
challengeId: this.challengeId,
});
$.export("$summary", "Successfully deleted the challenge with ID: " + this.challengeId);
return response;
},
};
26 changes: 26 additions & 0 deletions components/habitica/actions/get-challenge/get-challenge.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import app from "../../habitica.app.mjs";

export default {
key: "habitica-get-challenge",
name: "Get Challenge",
description: "Get data for the challenge with the specified ID. [See the documentation](https://habitica.com/apidoc/#api-Challenge-GetChallenge)",
version: "0.0.1",
type: "action",
props: {
app,
challengeId: {
propDefinition: [
app,
"challengeId",
],
},
},
async run({ $ }) {
const response = await this.app.getChallenge({
$,
challengeId: this.challengeId,
});
$.export("$summary", "Successfully retrieved the challenge with ID: " + this.challengeId);
return response;
},
};
13 changes: 0 additions & 13 deletions components/habitica/app/habitica.app.ts

This file was deleted.

9 changes: 9 additions & 0 deletions components/habitica/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
GROUP_TYPES: [
"party",
"guilds",
"privateGuilds",
"publicGuilds",
"tavern",
],
};
149 changes: 149 additions & 0 deletions components/habitica/habitica.app.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { axios } from "@pipedream/platform";
import constants from "./common/constants.mjs";

export default {
type: "app",
app: "habitica",
propDefinitions: {
group: {
type: "string",
label: "Group",
description: "ID of the group to which the challenge belongs",
async options({ type }) {
const response = await this.getGroups({
type,
});
const groups = response.data;
return groups.map(({
name, _id,
}) => ({
label: name,
value: _id,
}));
},
},
name: {
type: "string",
label: "Name",
description: "Full name of the challenge",
},
shortName: {
type: "string",
label: "Short Name",
description: "A shortened name for the challenge, to be used as a tag",
},
summary: {
type: "string",
label: "Summary",
description: "A short summary advertising the main purpose of the challenge",
optional: true,
},
description: {
type: "string",
label: "Description",
description: "A detailed description of the challenge",
optional: true,
},
official: {
type: "boolean",
label: "Official",
description: "Whether or not a challenge is an official Habitica challenge",
optional: true,
},
prize: {
type: "string",
label: "Prize",
description: "Number of gems offered as a prize to challenge winner",
optional: true,
},
type: {
type: "string",
label: "Type",
description: "Type of the group",
options: constants.GROUP_TYPES,
},
challengeId: {
type: "string",
label: "Challenge ID",
description: "ID of the challenge to update",
async options({ page }) {
const response = await this.getChallenges({
params: {
page: page,
},
});
const challenges = response.data;
return challenges.map(({
name, _id,
}) => ({
label: name,
value: _id,
}));
},
},
},
methods: {
_baseUrl() {
return "https://habitica.com/api/v3";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
...headers,
"x-client": "3a326108-1895-4c23-874e-37668c75f2ad-Pipedream",
"x-api-user": `${this.$auth.user_id}`,
"x-api-key": `${this.$auth.api_token}`,
},
});
},
async createChallenge(args = {}) {
return this._makeRequest({
path: "/challenges",
method: "post",
...args,
});
},
async deleteChallenge({
challengeId, ...args
}) {
return this._makeRequest({
path: `/challenges/${challengeId}`,
method: "delete",
...args,
});
},
async getChallenge({
challengeId, ...args
}) {
return this._makeRequest({
path: `/challenges/${challengeId}`,
...args,
});
},
async getGroups({
type, ...args
}) {
return this._makeRequest({
path: "/groups",
params: {
type: type,
},
...args,
});
},
async getChallenges(args = {}) {
return this._makeRequest({
path: "/challenges/user",
...args,
});
},
},
};
8 changes: 5 additions & 3 deletions components/habitica/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
{
"name": "@pipedream/habitica",
"version": "0.0.2",
"version": "0.1.0",
"description": "Pipedream Habitica Components",
"main": "dist/app/habitica.app.mjs",
"main": "habitica.app.mjs",
"keywords": [
"pipedream",
"habitica"
],
"files": ["dist"],
"homepage": "https://pipedream.com/apps/habitica",
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
Loading
Loading