-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
0dd3f83
commit 80f84e1
Showing
5 changed files
with
165 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.