@olastudio/social-media-sdk 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/expo.d.mts +1 -1
- package/dist/adapters/expo.d.ts +1 -1
- package/dist/adapters/index.d.mts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/{auth.types-DTXCyA56.d.mts → auth.types-Do2L11TO.d.mts} +1 -1
- package/dist/{auth.types-DTXCyA56.d.ts → auth.types-Do2L11TO.d.ts} +1 -1
- package/dist/core/index.d.mts +128 -5
- package/dist/core/index.d.ts +128 -5
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +229 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +229 -0
- package/dist/index.mjs.map +1 -1
- package/dist/{insights.types-DF2_r0L1.d.ts → insights.types-BCalhgkj.d.ts} +1 -1
- package/dist/{insights.types-5z7HJnbt.d.mts → insights.types-hLzNJATM.d.mts} +1 -1
- package/dist/providers/facebook/index.d.mts +109 -2
- package/dist/providers/facebook/index.d.ts +109 -2
- package/dist/providers/facebook/index.js +105 -0
- package/dist/providers/facebook/index.js.map +1 -1
- package/dist/providers/facebook/index.mjs +105 -0
- package/dist/providers/facebook/index.mjs.map +1 -1
- package/dist/providers/instagram/index.d.mts +141 -3
- package/dist/providers/instagram/index.d.ts +141 -3
- package/dist/providers/instagram/index.js +124 -0
- package/dist/providers/instagram/index.js.map +1 -1
- package/dist/providers/instagram/index.mjs +124 -0
- package/dist/providers/instagram/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -949,6 +949,111 @@ var FacebookAPI = class {
|
|
|
949
949
|
getApiVersion() {
|
|
950
950
|
return FACEBOOK_GRAPH_API_VERSION;
|
|
951
951
|
}
|
|
952
|
+
// ============= Messaging Methods =============
|
|
953
|
+
/**
|
|
954
|
+
* Get conversations (inbox) for a Facebook Page
|
|
955
|
+
* Requires `pages_messaging` permission
|
|
956
|
+
*
|
|
957
|
+
* @param pageId - Facebook Page ID
|
|
958
|
+
* @param options - Pagination and field options
|
|
959
|
+
* @returns Paginated list of conversations
|
|
960
|
+
*/
|
|
961
|
+
async getPageConversations(pageId, options = {}) {
|
|
962
|
+
try {
|
|
963
|
+
const defaultFields = [
|
|
964
|
+
"id",
|
|
965
|
+
"participants",
|
|
966
|
+
"updated_time",
|
|
967
|
+
"unread_count",
|
|
968
|
+
"snippet",
|
|
969
|
+
"can_reply",
|
|
970
|
+
"messages.limit(1){id,message,from,created_time}"
|
|
971
|
+
];
|
|
972
|
+
const params = {
|
|
973
|
+
fields: (options.fields || defaultFields).join(","),
|
|
974
|
+
limit: options.limit || 25
|
|
975
|
+
};
|
|
976
|
+
if (options.after) {
|
|
977
|
+
params.after = options.after;
|
|
978
|
+
}
|
|
979
|
+
const response = await this.get(`/${pageId}/conversations`, params);
|
|
980
|
+
return response;
|
|
981
|
+
} catch (error) {
|
|
982
|
+
throw new APIError(
|
|
983
|
+
`Failed to fetch page conversations: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
984
|
+
void 0,
|
|
985
|
+
"CONVERSATIONS_FETCH_ERROR",
|
|
986
|
+
error
|
|
987
|
+
);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Get messages from a specific conversation
|
|
992
|
+
*
|
|
993
|
+
* @param conversationId - Conversation ID
|
|
994
|
+
* @param options - Pagination options
|
|
995
|
+
* @returns Paginated list of messages
|
|
996
|
+
*/
|
|
997
|
+
async getConversationMessages(conversationId, options = {}) {
|
|
998
|
+
try {
|
|
999
|
+
const defaultFields = [
|
|
1000
|
+
"id",
|
|
1001
|
+
"message",
|
|
1002
|
+
"from",
|
|
1003
|
+
"to",
|
|
1004
|
+
"created_time",
|
|
1005
|
+
"attachments"
|
|
1006
|
+
];
|
|
1007
|
+
const params = {
|
|
1008
|
+
fields: (options.fields || defaultFields).join(","),
|
|
1009
|
+
limit: options.limit || 25
|
|
1010
|
+
};
|
|
1011
|
+
if (options.after) {
|
|
1012
|
+
params.after = options.after;
|
|
1013
|
+
}
|
|
1014
|
+
const response = await this.get(`/${conversationId}/messages`, params);
|
|
1015
|
+
return response;
|
|
1016
|
+
} catch (error) {
|
|
1017
|
+
throw new APIError(
|
|
1018
|
+
`Failed to fetch conversation messages: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1019
|
+
void 0,
|
|
1020
|
+
"MESSAGES_FETCH_ERROR",
|
|
1021
|
+
error
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Send a message in a conversation
|
|
1027
|
+
* Uses the Send API for Page messaging
|
|
1028
|
+
*
|
|
1029
|
+
* @param pageId - Facebook Page ID
|
|
1030
|
+
* @param recipientId - PSID (Page-Scoped User ID) of the recipient
|
|
1031
|
+
* @param message - Message text to send
|
|
1032
|
+
* @param pageAccessToken - Page access token with messaging permission
|
|
1033
|
+
* @returns Message send response
|
|
1034
|
+
*/
|
|
1035
|
+
async sendMessage(pageId, recipientId, message, pageAccessToken) {
|
|
1036
|
+
try {
|
|
1037
|
+
const body = {
|
|
1038
|
+
recipient: { id: recipientId },
|
|
1039
|
+
message: { text: message },
|
|
1040
|
+
messaging_type: "RESPONSE",
|
|
1041
|
+
access_token: pageAccessToken || this.accessToken
|
|
1042
|
+
};
|
|
1043
|
+
const response = await this.post(
|
|
1044
|
+
`/${pageId}/messages`,
|
|
1045
|
+
body
|
|
1046
|
+
);
|
|
1047
|
+
return response;
|
|
1048
|
+
} catch (error) {
|
|
1049
|
+
throw new APIError(
|
|
1050
|
+
`Failed to send message: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1051
|
+
void 0,
|
|
1052
|
+
"MESSAGE_SEND_ERROR",
|
|
1053
|
+
error
|
|
1054
|
+
);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
952
1057
|
};
|
|
953
1058
|
|
|
954
1059
|
// providers/facebook/auth/FacebookAuth.ts
|
|
@@ -1511,6 +1616,31 @@ var InstagramAPI = class {
|
|
|
1511
1616
|
);
|
|
1512
1617
|
}
|
|
1513
1618
|
}
|
|
1619
|
+
/**
|
|
1620
|
+
* Get comments for a media item
|
|
1621
|
+
* @param mediaId - Media ID
|
|
1622
|
+
* @param limit - Max number of comments to fetch (default: 25)
|
|
1623
|
+
* @returns Array of comments
|
|
1624
|
+
*/
|
|
1625
|
+
async getMediaComments(mediaId, limit = 25) {
|
|
1626
|
+
try {
|
|
1627
|
+
const response = await this.get(
|
|
1628
|
+
`/${mediaId}/comments`,
|
|
1629
|
+
{
|
|
1630
|
+
fields: "id,text,timestamp,username,like_count,from{id,username},replies{id,text,timestamp,username,like_count}",
|
|
1631
|
+
limit
|
|
1632
|
+
}
|
|
1633
|
+
);
|
|
1634
|
+
return response.data || [];
|
|
1635
|
+
} catch (error) {
|
|
1636
|
+
throw new APIError(
|
|
1637
|
+
`Failed to fetch comments: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1638
|
+
void 0,
|
|
1639
|
+
"COMMENTS_FETCH_ERROR",
|
|
1640
|
+
error
|
|
1641
|
+
);
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1514
1644
|
/**
|
|
1515
1645
|
* Get Instagram account insights
|
|
1516
1646
|
*/
|
|
@@ -1754,6 +1884,105 @@ var InstagramAPI = class {
|
|
|
1754
1884
|
getApiVersion() {
|
|
1755
1885
|
return FACEBOOK_GRAPH_API_VERSION;
|
|
1756
1886
|
}
|
|
1887
|
+
// ============= Messaging Methods =============
|
|
1888
|
+
/**
|
|
1889
|
+
* Get conversations (inbox) for an Instagram Professional account
|
|
1890
|
+
* Requires `instagram_manage_messages` permission
|
|
1891
|
+
*
|
|
1892
|
+
* @param instagramAccountId - Instagram Business/Creator Account ID
|
|
1893
|
+
* @param options - Pagination and field options
|
|
1894
|
+
* @returns Paginated list of conversations
|
|
1895
|
+
*/
|
|
1896
|
+
async getConversations(instagramAccountId, options = {}) {
|
|
1897
|
+
try {
|
|
1898
|
+
const defaultFields = [
|
|
1899
|
+
"id",
|
|
1900
|
+
"participants",
|
|
1901
|
+
"updated_time",
|
|
1902
|
+
"messages.limit(1){id,message,from,created_time}"
|
|
1903
|
+
];
|
|
1904
|
+
const params = {
|
|
1905
|
+
fields: (options.fields || defaultFields).join(","),
|
|
1906
|
+
limit: options.limit || 25
|
|
1907
|
+
};
|
|
1908
|
+
if (options.after) {
|
|
1909
|
+
params.after = options.after;
|
|
1910
|
+
}
|
|
1911
|
+
const response = await this.get(`/${instagramAccountId}/conversations`, params);
|
|
1912
|
+
return response;
|
|
1913
|
+
} catch (error) {
|
|
1914
|
+
throw new APIError(
|
|
1915
|
+
`Failed to fetch Instagram conversations: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1916
|
+
void 0,
|
|
1917
|
+
"CONVERSATIONS_FETCH_ERROR",
|
|
1918
|
+
error
|
|
1919
|
+
);
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Get messages from a specific Instagram conversation
|
|
1924
|
+
*
|
|
1925
|
+
* @param conversationId - Conversation ID
|
|
1926
|
+
* @param options - Pagination options
|
|
1927
|
+
* @returns Paginated list of messages
|
|
1928
|
+
*/
|
|
1929
|
+
async getConversationMessages(conversationId, options = {}) {
|
|
1930
|
+
try {
|
|
1931
|
+
const defaultFields = [
|
|
1932
|
+
"id",
|
|
1933
|
+
"message",
|
|
1934
|
+
"from",
|
|
1935
|
+
"to",
|
|
1936
|
+
"created_time",
|
|
1937
|
+
"attachments"
|
|
1938
|
+
];
|
|
1939
|
+
const params = {
|
|
1940
|
+
fields: (options.fields || defaultFields).join(","),
|
|
1941
|
+
limit: options.limit || 25
|
|
1942
|
+
};
|
|
1943
|
+
if (options.after) {
|
|
1944
|
+
params.after = options.after;
|
|
1945
|
+
}
|
|
1946
|
+
const response = await this.get(`/${conversationId}/messages`, params);
|
|
1947
|
+
return response;
|
|
1948
|
+
} catch (error) {
|
|
1949
|
+
throw new APIError(
|
|
1950
|
+
`Failed to fetch Instagram messages: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1951
|
+
void 0,
|
|
1952
|
+
"MESSAGES_FETCH_ERROR",
|
|
1953
|
+
error
|
|
1954
|
+
);
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
/**
|
|
1958
|
+
* Send a message to an Instagram user
|
|
1959
|
+
* Uses the Instagram Send API
|
|
1960
|
+
*
|
|
1961
|
+
* @param instagramAccountId - Instagram Business/Creator Account ID
|
|
1962
|
+
* @param recipientId - Instagram-scoped ID of the recipient
|
|
1963
|
+
* @param message - Message text to send
|
|
1964
|
+
* @returns Message send response
|
|
1965
|
+
*/
|
|
1966
|
+
async sendMessage(instagramAccountId, recipientId, message) {
|
|
1967
|
+
try {
|
|
1968
|
+
const body = {
|
|
1969
|
+
recipient: { id: recipientId },
|
|
1970
|
+
message: { text: message }
|
|
1971
|
+
};
|
|
1972
|
+
const response = await this.post(
|
|
1973
|
+
`/${instagramAccountId}/messages`,
|
|
1974
|
+
body
|
|
1975
|
+
);
|
|
1976
|
+
return response;
|
|
1977
|
+
} catch (error) {
|
|
1978
|
+
throw new APIError(
|
|
1979
|
+
`Failed to send Instagram message: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1980
|
+
void 0,
|
|
1981
|
+
"MESSAGE_SEND_ERROR",
|
|
1982
|
+
error
|
|
1983
|
+
);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1757
1986
|
};
|
|
1758
1987
|
|
|
1759
1988
|
// providers/instagram/InstagramProvider.ts
|