Skip to content

Commit 127a079

Browse files
committed
[Components] callerapi #14969
Actions - Get Phone Number Information - Get Phone Number Picture
1 parent 31c13a7 commit 127a079

File tree

4 files changed

+68
-50
lines changed

4 files changed

+68
-50
lines changed

components/callerapi/actions/get-phone-number-information/get-phone-number-information.mjs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import callerapi from "../../callerapi.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "callerapi-get-phone-number-information",
65
name: "Get Phone Number Information",
7-
description: "Retrieve detailed information about a specific phone number, including name, location, and carrier. [See the documentation](https://github.com/dimondevceo/caller-id-api)",
8-
version: "0.0.{{ts}}",
6+
description: "Retrieve detailed information about a specific phone number, including name, location, and carrier. [See the documentation](https://callerapi.com/documentation)",
7+
version: "0.0.1",
98
type: "action",
109
props: {
11-
callerapi: {
12-
type: "app",
13-
app: "callerapi",
14-
},
10+
callerapi,
1511
phoneNumber: {
16-
type: "string",
17-
label: "Phone Number",
18-
description: "The phone number to retrieve information for (E.164 format, e.g., +18006927753)",
12+
propDefinition: [
13+
callerapi,
14+
"phoneNumber",
15+
],
1916
},
2017
},
2118
async run({ $ }) {
22-
const response = await this.callerapi.getPhoneInfo(this.phoneNumber);
19+
const response = await this.callerapi.getPhoneInfo({
20+
$,
21+
phoneNumber: this.phoneNumber,
22+
});
2323
$.export("$summary", `Retrieved information for phone number ${this.phoneNumber}`);
2424
return response;
2525
},
Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import fs from "fs";
13
import callerapi from "../../callerapi.app.mjs";
2-
import { axios } from "@pipedream/platform";
34

45
export default {
56
key: "callerapi-get-phone-number-picture",
67
name: "Get Phone Number Picture",
7-
description: "Retrieve the profile picture associated with a phone number. [See the documentation]()",
8-
version: "0.0.{{ts}}",
8+
description: "Retrieve the profile picture associated with a phone number. [See the documentation](https://callerapi.com/documentation)",
9+
version: "0.0.1",
910
type: "action",
1011
props: {
11-
callerapi: {
12-
type: "app",
13-
app: "callerapi",
14-
},
12+
callerapi,
1513
phoneNumber: {
16-
type: "string",
17-
label: "Phone Number",
14+
propDefinition: [
15+
callerapi,
16+
"phoneNumber",
17+
],
1818
description: "The phone number to retrieve the profile picture for, in E.164 format (e.g., +18006927753)",
1919
},
2020
},
2121
async run({ $ }) {
22-
const response = await this.callerapi.getPhonePicture(this.phoneNumber);
23-
$.export("$summary", `Retrieved profile picture for ${this.phoneNumber}`);
24-
return response;
22+
try {
23+
const response = await this.callerapi.getPhonePicture({
24+
$,
25+
phoneNumber: this.phoneNumber,
26+
});
27+
const fileName = `CallerAPI-Pictgure-${Date.parse(new Date())}.png`;
28+
const buf = Buffer.from(response, "base64");
29+
fs.writeFileSync(`/tmp/${fileName}`, buf);
30+
31+
$.export("$summary", `The profile picture for ${this.phoneNumber} has been successfully retrieved and saved to the /tmp directory.`);
32+
return {
33+
path: `/tmp/${fileName}`,
34+
};
35+
} catch (e) {
36+
throw new ConfigurationError(e?.response?.data || e);
37+
}
2538
},
2639
};

components/callerapi/callerapi.app.mjs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,46 @@ import { axios } from "@pipedream/platform";
33
export default {
44
type: "app",
55
app: "callerapi",
6-
version: "0.0.1",
7-
propDefinitions: {},
8-
methods: {
9-
// this.$auth contains connected account data
10-
authKeys() {
11-
console.log(Object.keys(this.$auth));
6+
propDefinitions: {
7+
phoneNumber: {
8+
type: "string",
9+
label: "Phone Number",
10+
description: "The phone number to retrieve information for (E.164 format, e.g., +18006927753)",
1211
},
12+
},
13+
methods: {
1314
_baseUrl() {
14-
return "https://callerapi.com/api";
15+
return "https://callerapi.com/api/phone";
16+
},
17+
_headers() {
18+
return {
19+
"x-auth": this.$auth.api_key,
20+
};
1521
},
16-
async _makeRequest(opts = {}) {
17-
const {
18-
$ = this, method = "GET", path = "/", headers, ...otherOpts
19-
} = opts;
22+
_makeRequest({
23+
$ = this, method, path = "/", ...opts
24+
}) {
2025
return axios($, {
21-
...otherOpts,
26+
...opts,
2227
method,
2328
url: this._baseUrl() + path,
24-
headers: {
25-
...headers,
26-
"X-Auth": this.$auth.api_key,
27-
},
29+
headers: this._headers(),
2830
});
2931
},
30-
async getPhoneInfo(phoneNumber, opts = {}) {
31-
const phone = phoneNumber.replace(/^\+/, "");
32+
getPhoneInfo({
33+
$, phoneNumber,
34+
}) {
3235
return this._makeRequest({
33-
method: "GET",
34-
path: `/phone/info/${phone}`,
35-
...opts,
36+
$,
37+
path: `/info/${phoneNumber}`,
3638
});
3739
},
38-
async getPhonePicture(phoneNumber, opts = {}) {
39-
const phone = phoneNumber.replace(/^\+/, "");
40+
getPhonePicture({
41+
$, phoneNumber,
42+
}) {
4043
return this._makeRequest({
41-
method: "GET",
42-
path: `/phone/pic/${phone}`,
43-
...opts,
44+
$,
45+
path: `/pic/${phoneNumber}`,
4446
});
4547
},
4648
},

components/callerapi/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/callerapi",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream CallerAPI Components",
55
"main": "callerapi.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
1518
}

0 commit comments

Comments
 (0)