Skip to content

Commit

Permalink
[Components] myotp_app #12364 (#12404)
Browse files Browse the repository at this point in the history
* Added actions

* Fixed requested changes

* Update components/myotp_app/actions/send-otp/send-otp.mjs

---------

Co-authored-by: Leo Vu <18277920+vunguyenhung@users.noreply.github.com>
  • Loading branch information
lcaresia and vunguyenhung authored Jun 20, 2024
1 parent 0dd3f83 commit 80f84e1
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 8 deletions.
38 changes: 38 additions & 0 deletions components/myotp_app/actions/send-otp/send-otp.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import app from "../../myotp_app.app.mjs";

export default {
key: "myotp_app-send-otp",
name: "Send OTP",
description: "Generate a One Time Password (OTP) and send it to the specified phone number. [See the documentation](https://api.myotp.app/swagger-ui/#/default/generate_otp_endpoint)",
version: "0.0.1",
type: "action",
props: {
app,
phoneNumber: {
propDefinition: [
app,
"phoneNumber",
],
},
otpValidity: {
propDefinition: [
app,
"otpValidity",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.app.sendOTP({
$,
data: {
phone_number: this.phoneNumber,
otp_validity: this.otpValidity,
},
});

$.export("$summary", `Successfully sent OTP. Valid until '${response.expires_at}'`);

return response;
},
};
44 changes: 44 additions & 0 deletions components/myotp_app/actions/verify-otp/verify-otp.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import app from "../../myotp_app.app.mjs";

export default {
key: "myotp_app-verify-otp",
name: "Verify OTP",
description: "Validate the OTP for successful verification. [See the documentation](https://api.myotp.app/swagger-ui/#/default/verify_otp_endpoint)",
version: "0.0.1",
type: "action",
props: {
app,
phoneNumber: {
propDefinition: [
app,
"phoneNumber",
],
},
messageID: {
propDefinition: [
app,
"messageID",
],
},
otp: {
propDefinition: [
app,
"otp",
],
},
},
async run({ $ }) {
const response = await this.app.verifyOTP({
$,
data: {
phone_number: this.phoneNumber,
message_id: this.messageID,
otp: this.otp,
},
});

$.export("$summary", `Successfully verified OTP. Status: ${response.status}`);

return response;
},
};
79 changes: 74 additions & 5 deletions components/myotp_app/myotp_app.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,80 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "myotp_app",
propDefinitions: {},
propDefinitions: {
otpValidity: {
type: "integer",
label: "OTP Validity",
description: "Validity of the OTP",
},
phoneNumber: {
type: "string",
label: "Phone Number",
description: "Phone number to which the OTP will be sent",
},
messageID: {
type: "string",
label: "Message ID",
description: "ID of the OTP message",
async options() {
const response = await this.getReport({});
const messagesIDs = response.transactions;
return messagesIDs.map(({
message_id, phone_number,
}) => ({
value: message_id,
label: phone_number,
}));
},
},
otp: {
type: "string",
label: "OTP",
description: "One-time password sent to the phone number",
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://api.myotp.app";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
...headers,
"X-API-Key": `${this.$auth.api_key}`,
},
});
},
async sendOTP(args = {}) {
return this._makeRequest({
method: "post",
path: "/generate_otp",
...args,
});
},
async verifyOTP(args = {}) {
return this._makeRequest({
method: "post",
path: "/verify_otp",
...args,
});
},
async getReport(args = {}) {
return this._makeRequest({
method: "post",
path: "/report",
...args,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/myotp_app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/myotp_app",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream MyOTP.App Components",
"main": "myotp_app.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.0"
}
}
}
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 80f84e1

Please sign in to comment.