@oficialapi/sdk 9.0.6 → 9.0.7

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/README.md CHANGED
@@ -1642,10 +1642,24 @@ await sdk.webchat.sendButtons({
1642
1642
  #### Listar Posts
1643
1643
 
1644
1644
  ```typescript
1645
+ // Listar posts do Facebook
1645
1646
  const posts = await sdk.facebook.listPosts({
1646
1647
  channelToken: 'sk_live_...',
1647
- pageId: 'page_id',
1648
- limit: 10
1648
+ channelType: 'facebook',
1649
+ limit: 10,
1650
+ type: 'feed', // 'feed' | 'photos' | 'videos' | 'events'
1651
+ includeComments: false,
1652
+ includeReactions: false
1653
+ }, accessToken);
1654
+
1655
+ // Listar mídias do Instagram
1656
+ const instagramMedia = await sdk.facebook.listPosts({
1657
+ channelToken: 'sk_live_...',
1658
+ channelType: 'instagram',
1659
+ limit: 10,
1660
+ type: 'media',
1661
+ includeComments: false,
1662
+ includeReactions: false
1649
1663
  }, accessToken);
1650
1664
  ```
1651
1665
 
@@ -1663,9 +1677,22 @@ await sdk.facebook.createPost({
1663
1677
  #### Listar Comentários
1664
1678
 
1665
1679
  ```typescript
1680
+ // Listar comentários do Facebook
1666
1681
  const comments = await sdk.facebook.listComments({
1667
1682
  channelToken: 'sk_live_...',
1683
+ channelType: 'facebook',
1668
1684
  postId: 'post_id',
1685
+ limit: 20,
1686
+ order: 'created_time', // 'created_time' | 'like_count'
1687
+ filterUnanswered: false,
1688
+ includeReplies: false
1689
+ }, accessToken);
1690
+
1691
+ // Listar comentários do Instagram
1692
+ const instagramComments = await sdk.facebook.listComments({
1693
+ channelToken: 'sk_live_...',
1694
+ channelType: 'instagram',
1695
+ postId: 'media_id',
1669
1696
  limit: 20
1670
1697
  }, accessToken);
1671
1698
  ```
package/dist/index.d.mts CHANGED
@@ -583,13 +583,23 @@ interface SendWebChatButtonsParams {
583
583
  }
584
584
  interface ListPostsParams {
585
585
  channelToken: string;
586
- pageId: string;
586
+ channelType: 'facebook' | 'instagram';
587
+ pageId?: string;
587
588
  limit?: number;
589
+ after?: string;
590
+ type?: 'feed' | 'photos' | 'videos' | 'events' | 'media';
591
+ includeComments?: boolean;
592
+ includeReactions?: boolean;
588
593
  }
589
594
  interface ListCommentsParams {
590
595
  channelToken: string;
596
+ channelType: 'facebook' | 'instagram';
591
597
  postId: string;
592
598
  limit?: number;
599
+ after?: string;
600
+ order?: 'created_time' | 'like_count';
601
+ filterUnanswered?: boolean;
602
+ includeReplies?: boolean;
593
603
  }
594
604
  interface CreatePostParams {
595
605
  channelToken: string;
package/dist/index.d.ts CHANGED
@@ -583,13 +583,23 @@ interface SendWebChatButtonsParams {
583
583
  }
584
584
  interface ListPostsParams {
585
585
  channelToken: string;
586
- pageId: string;
586
+ channelType: 'facebook' | 'instagram';
587
+ pageId?: string;
587
588
  limit?: number;
589
+ after?: string;
590
+ type?: 'feed' | 'photos' | 'videos' | 'events' | 'media';
591
+ includeComments?: boolean;
592
+ includeReactions?: boolean;
588
593
  }
589
594
  interface ListCommentsParams {
590
595
  channelToken: string;
596
+ channelType: 'facebook' | 'instagram';
591
597
  postId: string;
592
598
  limit?: number;
599
+ after?: string;
600
+ order?: 'created_time' | 'like_count';
601
+ filterUnanswered?: boolean;
602
+ includeReplies?: boolean;
593
603
  }
594
604
  interface CreatePostParams {
595
605
  channelToken: string;
package/dist/index.js CHANGED
@@ -3,6 +3,6 @@
3
3
  * @version 1.0.0
4
4
  * @license MIT
5
5
  */
6
- var I="https://api.oficialapi.com.br",l=class{constructor(e){this.config={clientId:e.clientId,clientSecret:e.clientSecret,timeout:e.timeout||3e4,maxRetries:e.maxRetries||3,retryDelay:e.retryDelay||1e3,headers:e.headers||{}},this.axiosInstance=P__default.default.create({baseURL:I,timeout:this.config.timeout,headers:{"Content-Type":"application/json",...this.config.headers}}),this.setupInterceptors();}setupInterceptors(){this.axiosInstance.interceptors.request.use(e=>{if(e.url?.includes("/auth/token"))return e;let t=e;return t.accessToken&&e.headers&&(e.headers.Authorization=`Bearer ${t.accessToken}`),e},e=>Promise.reject(e)),this.axiosInstance.interceptors.response.use(e=>e,async e=>{let t=e.config;if(!t)return Promise.reject(this.formatError(e));if((!e.response||e.response.status>=500&&e.response.status<600)&&(!t._retryCount||t._retryCount<this.config.maxRetries)){t._retryCount=(t._retryCount||0)+1;let s=this.config.retryDelay*t._retryCount;return await new Promise(i=>setTimeout(i,s)),this.axiosInstance(t)}return Promise.reject(this.formatError(e))});}formatError(e){if(e.response){let t=e.response.data,n=t?.error?.message||t?.message||e.message,s=t?.error?.details||[],i=new Error(n);return i.status=e.response.status,i.data=e.response.data,i.details=s,i}return e.request?new Error("Erro de conex\xE3o com a API. Verifique sua conex\xE3o com a internet."):e}async get(e,t,n){let s={...n,accessToken:t};return (await this.axiosInstance.get(e,s)).data}async post(e,t,n,s){let i={...s,accessToken:n};return (await this.axiosInstance.post(e,t,i)).data}async put(e,t,n,s){let i={...s,accessToken:n};return (await this.axiosInstance.put(e,t,i)).data}async delete(e,t,n,s){let i={...s,accessToken:t,data:n};return (await this.axiosInstance.delete(e,i)).data}async upload(e,t,n,s="file",i){let o=new FormData;if(t instanceof Buffer){let y=new Blob([t]);o.append(s,y);}else o.append(s,t);i&&Object.entries(i).forEach(([y,r])=>{r!=null&&o.append(y,typeof r=="string"?r:JSON.stringify(r));});let C={headers:{"Content-Type":"multipart/form-data"},accessToken:n};return (await this.axiosInstance.post(e,o,C)).data}};var d=class{constructor(e){this.httpClient=e;}async getToken(e,t){let n=await this.httpClient.post("/api/v1/auth/token",{client_id:e,client_secret:t});if(!n.success||!n.data)throw new Error(n.error?.message||"Falha ao obter token");return n.data}};var c=class{constructor(e){this.httpClient=e;}async list(e){let t=await this.httpClient.get("/api/v1/channels",e);if(!t.success||!t.data)throw new Error(t.error?.message||"Falha ao listar canais");return Array.isArray(t.data)?t.data:[t.data]}};var h=class{constructor(e){this.httpClient=e;}async createWebhook(e,t){let n=await this.httpClient.post("/api/v1/integrations",{url:e.url,expiresInDays:e.expiresInDays},t);if(!n.success||!n.data)throw new Error(n.error?.message||"Falha ao criar webhook");return n.data}};var p=class{constructor(e){this.httpClient=e;}async sendText(e,t){return this.httpClient.post("/api/v1/whatsapp/send-message",{channelToken:e.channelToken,sender:e.sender,messageText:e.messageText},t)}async sendMedia(e,t){return this.httpClient.post("/api/v1/whatsapp/send-media",{channelToken:e.channelToken,sender:e.sender,fileUrl:e.fileUrl,type:e.type,caption:e.caption,...e.fileName&&{fileName:e.fileName}},t)}async sendTemplate(e,t){return this.httpClient.post("/api/v1/whatsapp/send-template",{channelToken:e.channelToken,sender:e.sender,templateName:e.templateName,languageCode:e.languageCode,components:e.components},t)}async sendButtons(e,t){return this.httpClient.post("/api/v1/whatsapp/send-buttons",{channelToken:e.channelToken,sender:e.sender,text:e.text,buttons:e.buttons,...e.media&&{media:e.media}},t)}async sendList(e,t){return this.httpClient.post("/api/v1/whatsapp/send-list",{channelToken:e.channelToken,sender:e.sender,headerText:e.headerText,bodyText:e.bodyText,buttonText:e.buttonText,sections:e.sections,...e.footerText&&{footerText:e.footerText}},t)}async replyMessage(e,t){return this.httpClient.post("/api/v1/whatsapp/reply-message",{channelToken:e.channelToken,sender:e.sender,messageText:e.messageText,...e.replyMessageId&&{replyMessageId:e.replyMessageId},...e.preview_url!==void 0&&{preview_url:e.preview_url}},t)}async reactMessage(e,t){return this.httpClient.post("/api/v1/whatsapp/react-message",{channelToken:e.channelToken,sender:e.sender,emoji:e.emoji,...e.message_id&&{message_id:e.message_id}},t)}async createTemplate(e,t){return this.httpClient.post("/api/v1/whatsapp/create-template",{channelToken:e.channelToken,name:e.name,language:e.language,category:e.category,components:e.components},t)}async listTemplates(e,t){return this.httpClient.get(`/api/v1/whatsapp/templates?channelToken=${encodeURIComponent(e)}`,t)}async getTemplate(e,t,n){return this.httpClient.get(`/api/v1/whatsapp/templates/${t}?channelToken=${encodeURIComponent(e)}`,n)}async uploadMedia(e,t){return this.httpClient.upload("/api/v1/whatsapp/upload-media",e.file,t,"file",{channelToken:e.channelToken,mediaType:e.mediaType,...e.filename&&{filename:e.filename}})}async sendOrderDetails(e,t){return this.httpClient.post("/api/v1/whatsapp/send-order-details",{channelToken:e.channelToken,sender:e.sender,...e.headerText&&{headerText:e.headerText},bodyText:e.bodyText,...e.footerText&&{footerText:e.footerText},reference_id:e.reference_id,type:e.type,currency:e.currency,total_amount:e.total_amount,order:e.order,...e.payment_settings&&{payment_settings:e.payment_settings}},t)}async sendOrderStatus(e,t){return this.httpClient.post("/api/v1/whatsapp/send-order-status",{channelToken:e.channelToken,sender:e.sender,bodyText:e.bodyText,...e.footerText&&{footerText:e.footerText},reference_id:e.reference_id,order_status:e.order_status,...e.status_description&&{status_description:e.status_description},...e.payment_status&&{payment_status:e.payment_status},...e.payment_timestamp!==void 0&&{payment_timestamp:e.payment_timestamp}},t)}async sendAudio(e,t){return this.httpClient.post("/api/v1/whatsapp/send-audio",{channelToken:e.channelToken,sender:e.sender,mediaId:e.mediaId,...e.voice!==void 0&&{voice:e.voice}},t)}async sendSticker(e,t){return this.httpClient.post("/api/v1/whatsapp/send-sticker",{channelToken:e.channelToken,sender:e.sender,mediaId:e.mediaId},t)}async sendVideo(e,t){return this.httpClient.post("/api/v1/whatsapp/send-video",{channelToken:e.channelToken,sender:e.sender,mediaId:e.mediaId,...e.caption&&{caption:e.caption}},t)}async sendDocument(e,t){return this.httpClient.post("/api/v1/whatsapp/send-document",{channelToken:e.channelToken,sender:e.sender,mediaId:e.mediaId,...e.filename&&{filename:e.filename},...e.caption&&{caption:e.caption}},t)}async sendContact(e,t){return this.httpClient.post("/api/v1/whatsapp/send-contact",{channelToken:e.channelToken,sender:e.sender,contacts:e.contacts},t)}async sendLocation(e,t){return this.httpClient.post("/api/v1/whatsapp/send-location",{channelToken:e.channelToken,sender:e.sender,latitude:e.latitude,longitude:e.longitude,name:e.name,address:e.address},t)}async sendLocationRequest(e,t){return this.httpClient.post("/api/v1/whatsapp/send-location-request",{channelToken:e.channelToken,sender:e.sender,bodyText:e.bodyText,...e.headerText&&{headerText:e.headerText},...e.footerText&&{footerText:e.footerText}},t)}async sendCtaUrl(e,t){return this.httpClient.post("/api/v1/whatsapp/send-cta-url",{channelToken:e.channelToken,sender:e.sender,bodyText:e.bodyText,buttonText:e.buttonText,url:e.url,...e.header&&{header:e.header},...e.footerText&&{footerText:e.footerText}},t)}async sendMediaCarousel(e,t){return this.httpClient.post("/api/v1/whatsapp/send-media-carousel",{channelToken:e.channelToken,sender:e.sender,bodyText:e.bodyText,cards:e.cards},t)}async downloadMedia(e,t){return this.httpClient.post("/api/v1/whatsapp/download-media",{channelToken:e.channelToken,url:e.url},t)}};var g=class{constructor(e){this.httpClient=e;}async sendMessage(e,t){return this.httpClient.post("/api/v1/telegram/send-message",{channelToken:e.channelToken,chatId:e.chatId,text:e.text,parseMode:e.parseMode,replyToMessageId:e.replyToMessageId,disableNotification:e.disableNotification},t)}async sendMedia(e,t){return this.httpClient.post("/api/v1/telegram/send-media",{channelToken:e.channelToken,chatId:e.chatId,fileUrl:e.fileUrl,type:e.type,caption:e.caption,parseMode:e.parseMode,replyToMessageId:e.replyToMessageId},t)}async sendButtons(e,t){return this.httpClient.post("/api/v1/telegram/send-buttons",{channelToken:e.channelToken,chatId:e.chatId,text:e.text,buttons:e.buttons,parseMode:e.parseMode},t)}async sendLocation(e,t){return this.httpClient.post("/api/v1/telegram/send-location",{channelToken:e.channelToken,chatId:e.chatId,latitude:e.latitude,longitude:e.longitude,livePeriod:e.livePeriod},t)}async sendContact(e,t){return this.httpClient.post("/api/v1/telegram/send-contact",{channelToken:e.channelToken,chatId:e.chatId,phoneNumber:e.phoneNumber,firstName:e.firstName,lastName:e.lastName,vcard:e.vcard},t)}async sendPoll(e,t){return this.httpClient.post("/api/v1/telegram/send-poll",{channelToken:e.channelToken,chatId:e.chatId,question:e.question,options:e.options,isAnonymous:e.isAnonymous,type:e.type,correctOptionId:e.correctOptionId},t)}async sendVenue(e,t){return this.httpClient.post("/api/v1/telegram/send-venue",{channelToken:e.channelToken,chatId:e.chatId,latitude:e.latitude,longitude:e.longitude,title:e.title,address:e.address,foursquareId:e.foursquareId},t)}async sendDice(e,t){return this.httpClient.post("/api/v1/telegram/send-dice",{channelToken:e.channelToken,chatId:e.chatId,emoji:e.emoji},t)}async sendSticker(e,t){return this.httpClient.post("/api/v1/telegram/send-sticker",{channelToken:e.channelToken,chatId:e.chatId,stickerUrl:e.stickerUrl},t)}async sendVoice(e,t){return this.httpClient.post("/api/v1/telegram/send-voice",{channelToken:e.channelToken,chatId:e.chatId,voiceUrl:e.voiceUrl,caption:e.caption,duration:e.duration},t)}async sendVideoNote(e,t){return this.httpClient.post("/api/v1/telegram/send-video-note",{channelToken:e.channelToken,chatId:e.chatId,videoNoteUrl:e.videoNoteUrl,duration:e.duration,length:e.length},t)}async sendMediaGroup(e,t){return this.httpClient.post("/api/v1/telegram/send-media-group",{channelToken:e.channelToken,chatId:e.chatId,media:e.media},t)}async sendReplyKeyboard(e,t){return this.httpClient.post("/api/v1/telegram/send-reply-keyboard",{channelToken:e.channelToken,chatId:e.chatId,text:e.text,keyboard:e.keyboard,resizeKeyboard:e.resizeKeyboard,oneTimeKeyboard:e.oneTimeKeyboard},t)}async editMessage(e,t){return this.httpClient.post("/api/v1/telegram/edit-message",{channelToken:e.channelToken,chatId:e.chatId,messageId:e.messageId,text:e.text,parseMode:e.parseMode},t)}async deleteMessage(e,t){return this.httpClient.post("/api/v1/telegram/delete-message",{channelToken:e.channelToken,chatId:e.chatId,messageId:e.messageId},t)}async downloadMedia(e,t){return this.httpClient.post("/api/v1/telegram/download-media",{channelToken:e.channelToken,fileId:e.fileId},t)}};var u=class{constructor(e){this.httpClient=e;}async sendText(e,t){return this.httpClient.post("/api/v1/webchat/send-text",{channelToken:e.channelToken,chatId:e.chatId,type:"text",content:{text:e.messageText,typingTime:e.typingTime},typing:e.typing},t)}async sendMedia(e,t){return this.httpClient.post("/api/v1/webchat/send-media",{channelToken:e.channelToken,chatId:e.chatId,type:e.type,content:{url:e.fileUrl,caption:e.caption,typingTime:e.typingTime},typing:e.typing},t)}async sendCarousel(e,t){return this.httpClient.post("/api/v1/webchat/send-carousel",{channelToken:e.channelToken,chatId:e.chatId,type:"carousel",content:{cards:e.cards.map(n=>({title:n.title,subtitle:n.subtitle,imageUrl:n.imageUrl,buttons:n.buttons?.map(s=>({id:s.id||`btn_${Date.now()}_${Math.random()}`,text:s.text,type:s.type,value:s.value,url:s.url}))})),typingTime:e.typingTime},typing:e.typing},t)}async sendForm(e,t){return this.httpClient.post("/api/v1/webchat/send-form",{channelToken:e.channelToken,chatId:e.chatId,type:"form",content:{id:e.id,title:e.title,submitText:e.submitButtonText,fields:e.fields.map(n=>({id:n.id||n.name,type:n.type,label:n.label,placeholder:n.placeholder,required:n.required,options:n.options})),typingTime:e.typingTime},typing:e.typing},t)}async sendQuickReplies(e,t){return this.httpClient.post("/api/v1/webchat/send-quick-replies",{channelToken:e.channelToken,chatId:e.chatId,type:"quickReplies",content:{text:e.messageText,quickReplies:e.quickReplies.map(n=>({id:n.id||`qr_${Date.now()}_${Math.random()}`,text:n.text,value:n.value})),typingTime:e.typingTime},typing:e.typing},t)}async sendCard(e,t){return this.httpClient.post("/api/v1/webchat/send-card",{channelToken:e.channelToken,chatId:e.chatId,type:"card",content:{title:e.title,subtitle:e.description,imageUrl:e.imageUrl,buttons:e.buttons?.map(n=>({id:n.id||`btn_${Date.now()}_${Math.random()}`,text:n.text,type:n.type,value:n.value,url:n.url})),typingTime:e.typingTime},typing:e.typing},t)}async sendButtons(e,t){return this.httpClient.post("/api/v1/webchat/send-buttons",{channelToken:e.channelToken,chatId:e.chatId,type:"buttons",content:{text:e.messageText,buttons:e.buttons.map(n=>({id:n.id||`btn_${Date.now()}_${Math.random()}`,text:n.text,type:n.type,value:n.value,url:n.url})),typingTime:e.typingTime},typing:e.typing},t)}};var m=class{constructor(e){this.httpClient=e;}async listPosts(e,t){return this.httpClient.post("/api/v1/facebook/list-posts",{channelToken:e.channelToken,pageId:e.pageId,limit:e.limit},t)}async listComments(e,t){return this.httpClient.post("/api/v1/facebook/list-comments",{channelToken:e.channelToken,postId:e.postId,limit:e.limit},t)}async createPost(e,t){return this.httpClient.post("/api/v1/facebook/create-post",{channelToken:e.channelToken,pageId:e.pageId,message:e.message,link:e.link},t)}async replyComment(e,t){return this.httpClient.post("/api/v1/facebook/reply-comment",{channelToken:e.channelToken,commentId:e.commentId,message:e.message},t)}async deleteComment(e,t){return this.httpClient.post("/api/v1/facebook/delete-comment",{channelToken:e.channelToken,commentId:e.commentId},t)}async sendText(e,t){return this.httpClient.post("/api/v1/facebook/send-text",{channelToken:e.channelToken,recipientId:e.recipientId,message:e.message},t)}async sendMedia(e,t){return this.httpClient.post("/api/v1/facebook/send-media",{channelToken:e.channelToken,recipientId:e.recipientId,fileUrl:e.fileUrl,type:e.type,caption:e.caption},t)}async sendButtons(e,t){return this.httpClient.post("/api/v1/facebook/send-buttons",{channelToken:e.channelToken,recipientId:e.recipientId,message:e.message,buttons:e.buttons},t)}async sendSticker(e,t){return this.httpClient.post("/api/v1/facebook/send-sticker",{channelToken:e.channelToken,recipientId:e.recipientId,stickerId:e.stickerId},t)}async replyMessage(e,t){return this.httpClient.post("/api/v1/facebook/reply-message",{channelToken:e.channelToken,messageId:e.messageId,message:e.message},t)}async replyMedia(e,t){return this.httpClient.post("/api/v1/facebook/reply-media",{channelToken:e.channelToken,messageId:e.messageId,fileUrl:e.fileUrl,type:e.type,caption:e.caption},t)}async sharePost(e,t){return this.httpClient.post("/api/v1/facebook/share-post",{channelToken:e.channelToken,mediaId:e.mediaId,recipientId:e.recipientId},t)}async getUserProfile(e,t){return this.httpClient.post("/api/v1/facebook/user-profile",{channelToken:e.channelToken,userId:e.userId},t)}async getPageProfile(e,t){return this.httpClient.post("/api/v1/facebook/page-profile",{channelToken:e.channelToken,pageId:e.pageId},t)}async downloadMedia(e,t){return this.httpClient.post("/api/v1/facebook/download-media",{channelToken:e.channelToken,url:e.url},t)}};var T=class{constructor(e){this.httpClient=e;}async sendPrivateReply(e,t){return this.httpClient.post("/api/v1/instagram/private-reply",{channelToken:e.channelToken,commentId:e.commentId,message:e.message},t)}async sendText(e,t){return this.httpClient.post("/api/v1/instagram/messages/text",{channelToken:e.channelToken,recipientId:e.recipientId,text:e.text,...e.tags&&{tags:e.tags}},t)}async sendMedia(e,t){return this.httpClient.post("/api/v1/instagram/messages/media",{channelToken:e.channelToken,recipientId:e.recipientId,attachment:e.attachment,...e.tags&&{tags:e.tags}},t)}async sendImages(e,t){return this.httpClient.post("/api/v1/instagram/messages/images",{channelToken:e.channelToken,recipientId:e.recipientId,images:e.images},t)}async sendSticker(e,t){return this.httpClient.post("/api/v1/instagram/messages/sticker",{channelToken:e.channelToken,recipientId:e.recipientId,stickerType:e.stickerType},t)}async reactMessage(e,t){return this.httpClient.post("/api/v1/instagram/messages/reaction",{channelToken:e.channelToken,messageId:e.messageId,reactionType:e.reactionType},t)}async removeReaction(e,t){return this.httpClient.delete("/api/v1/instagram/messages/reaction",t,{channelToken:e.channelToken,recipientId:e.recipientId,messageId:e.messageId})}async sendQuickReplies(e,t){return this.httpClient.post("/api/v1/instagram/messages/quick-replies",{channelToken:e.channelToken,recipientId:e.recipientId,message:e.message,quickReplies:e.quickReplies},t)}async sendGenericTemplate(e,t){return this.httpClient.post("/api/v1/instagram/messages/generic-template",{channelToken:e.channelToken,recipientId:e.recipientId,elements:e.elements},t)}async sendButtonTemplate(e,t){return this.httpClient.post("/api/v1/instagram/messages/button-template",{channelToken:e.channelToken,recipientId:e.recipientId,text:e.text,buttons:e.buttons},t)}async sendSenderAction(e,t){return this.httpClient.post("/api/v1/instagram/messages/sender-action",{channelToken:e.channelToken,recipientId:e.recipientId,action:e.action},t)}async getUserProfile(e,t){return this.httpClient.post("/api/v1/instagram/user-profile",{channelToken:e.channelToken,userId:e.userId},t)}async listPosts(e,t){return this.httpClient.post("/api/v1/instagram/posts",{channelToken:e.channelToken,userId:e.userId,limit:e.limit},t)}async getBusinessProfile(e,t){return this.httpClient.post("/api/v1/instagram/business-profile",{channelToken:e.channelToken},t)}async downloadMedia(e,t){return this.httpClient.post("/api/v1/instagram/download-media",{channelToken:e.channelToken,url:e.url},t)}async createMediaContainer(e,t){return this.httpClient.post("/api/v1/instagram/media",{channelToken:e.channelToken,image_url:e.image_url,video_url:e.video_url,media_type:e.media_type,caption:e.caption,is_carousel_item:e.is_carousel_item,children:e.children,upload_type:e.upload_type,trial_params:e.trial_params,alt_text:e.alt_text,location_id:e.location_id,product_tags:e.product_tags,user_tags:e.user_tags},t)}async publishMedia(e,t){return this.httpClient.post("/api/v1/instagram/media_publish",{channelToken:e.channelToken,creation_id:e.creation_id},t)}async getContainerStatus(e,t){return this.httpClient.post(`/api/v1/instagram/media/${e.container_id}/status`,{channelToken:e.channelToken},t)}async getPublishingLimit(e,t){return this.httpClient.post("/api/v1/instagram/content_publishing_limit",{channelToken:e.channelToken},t)}async uploadVideo(e,t){return this.httpClient.post("/api/v1/instagram/upload",{channelToken:e.channelToken,container_id:e.container_id,file_url:e.file_url,offset:e.offset,file_size:e.file_size},t)}};var k=class{constructor(e){this.httpClient=new l(e),this.auth=new d(this.httpClient),this.channels=new c(this.httpClient),this.integrations=new h(this.httpClient),this.whatsapp=new p(this.httpClient),this.telegram=new g(this.httpClient),this.webchat=new u(this.httpClient),this.facebook=new m(this.httpClient),this.instagram=new T(this.httpClient);}},K=k;
6
+ var I="https://api.oficialapi.com.br",l=class{constructor(e){this.config={clientId:e.clientId,clientSecret:e.clientSecret,timeout:e.timeout||3e4,maxRetries:e.maxRetries||3,retryDelay:e.retryDelay||1e3,headers:e.headers||{}},this.axiosInstance=P__default.default.create({baseURL:I,timeout:this.config.timeout,headers:{"Content-Type":"application/json",...this.config.headers}}),this.setupInterceptors();}setupInterceptors(){this.axiosInstance.interceptors.request.use(e=>{if(e.url?.includes("/auth/token"))return e;let t=e;return t.accessToken&&e.headers&&(e.headers.Authorization=`Bearer ${t.accessToken}`),e},e=>Promise.reject(e)),this.axiosInstance.interceptors.response.use(e=>e,async e=>{let t=e.config;if(!t)return Promise.reject(this.formatError(e));if((!e.response||e.response.status>=500&&e.response.status<600)&&(!t._retryCount||t._retryCount<this.config.maxRetries)){t._retryCount=(t._retryCount||0)+1;let s=this.config.retryDelay*t._retryCount;return await new Promise(i=>setTimeout(i,s)),this.axiosInstance(t)}return Promise.reject(this.formatError(e))});}formatError(e){if(e.response){let t=e.response.data,n=t?.error?.message||t?.message||e.message,s=t?.error?.details||[],i=new Error(n);return i.status=e.response.status,i.data=e.response.data,i.details=s,i}return e.request?new Error("Erro de conex\xE3o com a API. Verifique sua conex\xE3o com a internet."):e}async get(e,t,n){let s={...n,accessToken:t};return (await this.axiosInstance.get(e,s)).data}async post(e,t,n,s){let i={...s,accessToken:n};return (await this.axiosInstance.post(e,t,i)).data}async put(e,t,n,s){let i={...s,accessToken:n};return (await this.axiosInstance.put(e,t,i)).data}async delete(e,t,n,s){let i={...s,accessToken:t,data:n};return (await this.axiosInstance.delete(e,i)).data}async upload(e,t,n,s="file",i){let o=new FormData;if(t instanceof Buffer){let y=new Blob([t]);o.append(s,y);}else o.append(s,t);i&&Object.entries(i).forEach(([y,r])=>{r!=null&&o.append(y,typeof r=="string"?r:JSON.stringify(r));});let C={headers:{"Content-Type":"multipart/form-data"},accessToken:n};return (await this.axiosInstance.post(e,o,C)).data}};var d=class{constructor(e){this.httpClient=e;}async getToken(e,t){let n=await this.httpClient.post("/api/v1/auth/token",{client_id:e,client_secret:t});if(!n.success||!n.data)throw new Error(n.error?.message||"Falha ao obter token");return n.data}};var c=class{constructor(e){this.httpClient=e;}async list(e){let t=await this.httpClient.get("/api/v1/channels",e);if(!t.success||!t.data)throw new Error(t.error?.message||"Falha ao listar canais");return Array.isArray(t.data)?t.data:[t.data]}};var h=class{constructor(e){this.httpClient=e;}async createWebhook(e,t){let n=await this.httpClient.post("/api/v1/integrations",{url:e.url,expiresInDays:e.expiresInDays},t);if(!n.success||!n.data)throw new Error(n.error?.message||"Falha ao criar webhook");return n.data}};var p=class{constructor(e){this.httpClient=e;}async sendText(e,t){return this.httpClient.post("/api/v1/whatsapp/send-message",{channelToken:e.channelToken,sender:e.sender,messageText:e.messageText},t)}async sendMedia(e,t){return this.httpClient.post("/api/v1/whatsapp/send-media",{channelToken:e.channelToken,sender:e.sender,fileUrl:e.fileUrl,type:e.type,caption:e.caption,...e.fileName&&{fileName:e.fileName}},t)}async sendTemplate(e,t){return this.httpClient.post("/api/v1/whatsapp/send-template",{channelToken:e.channelToken,sender:e.sender,templateName:e.templateName,languageCode:e.languageCode,components:e.components},t)}async sendButtons(e,t){return this.httpClient.post("/api/v1/whatsapp/send-buttons",{channelToken:e.channelToken,sender:e.sender,text:e.text,buttons:e.buttons,...e.media&&{media:e.media}},t)}async sendList(e,t){return this.httpClient.post("/api/v1/whatsapp/send-list",{channelToken:e.channelToken,sender:e.sender,headerText:e.headerText,bodyText:e.bodyText,buttonText:e.buttonText,sections:e.sections,...e.footerText&&{footerText:e.footerText}},t)}async replyMessage(e,t){return this.httpClient.post("/api/v1/whatsapp/reply-message",{channelToken:e.channelToken,sender:e.sender,messageText:e.messageText,...e.replyMessageId&&{replyMessageId:e.replyMessageId},...e.preview_url!==void 0&&{preview_url:e.preview_url}},t)}async reactMessage(e,t){return this.httpClient.post("/api/v1/whatsapp/react-message",{channelToken:e.channelToken,sender:e.sender,emoji:e.emoji,...e.message_id&&{message_id:e.message_id}},t)}async createTemplate(e,t){return this.httpClient.post("/api/v1/whatsapp/create-template",{channelToken:e.channelToken,name:e.name,language:e.language,category:e.category,components:e.components},t)}async listTemplates(e,t){return this.httpClient.get(`/api/v1/whatsapp/templates?channelToken=${encodeURIComponent(e)}`,t)}async getTemplate(e,t,n){return this.httpClient.get(`/api/v1/whatsapp/templates/${t}?channelToken=${encodeURIComponent(e)}`,n)}async uploadMedia(e,t){return this.httpClient.upload("/api/v1/whatsapp/upload-media",e.file,t,"file",{channelToken:e.channelToken,mediaType:e.mediaType,...e.filename&&{filename:e.filename}})}async sendOrderDetails(e,t){return this.httpClient.post("/api/v1/whatsapp/send-order-details",{channelToken:e.channelToken,sender:e.sender,...e.headerText&&{headerText:e.headerText},bodyText:e.bodyText,...e.footerText&&{footerText:e.footerText},reference_id:e.reference_id,type:e.type,currency:e.currency,total_amount:e.total_amount,order:e.order,...e.payment_settings&&{payment_settings:e.payment_settings}},t)}async sendOrderStatus(e,t){return this.httpClient.post("/api/v1/whatsapp/send-order-status",{channelToken:e.channelToken,sender:e.sender,bodyText:e.bodyText,...e.footerText&&{footerText:e.footerText},reference_id:e.reference_id,order_status:e.order_status,...e.status_description&&{status_description:e.status_description},...e.payment_status&&{payment_status:e.payment_status},...e.payment_timestamp!==void 0&&{payment_timestamp:e.payment_timestamp}},t)}async sendAudio(e,t){return this.httpClient.post("/api/v1/whatsapp/send-audio",{channelToken:e.channelToken,sender:e.sender,mediaId:e.mediaId,...e.voice!==void 0&&{voice:e.voice}},t)}async sendSticker(e,t){return this.httpClient.post("/api/v1/whatsapp/send-sticker",{channelToken:e.channelToken,sender:e.sender,mediaId:e.mediaId},t)}async sendVideo(e,t){return this.httpClient.post("/api/v1/whatsapp/send-video",{channelToken:e.channelToken,sender:e.sender,mediaId:e.mediaId,...e.caption&&{caption:e.caption}},t)}async sendDocument(e,t){return this.httpClient.post("/api/v1/whatsapp/send-document",{channelToken:e.channelToken,sender:e.sender,mediaId:e.mediaId,...e.filename&&{filename:e.filename},...e.caption&&{caption:e.caption}},t)}async sendContact(e,t){return this.httpClient.post("/api/v1/whatsapp/send-contact",{channelToken:e.channelToken,sender:e.sender,contacts:e.contacts},t)}async sendLocation(e,t){return this.httpClient.post("/api/v1/whatsapp/send-location",{channelToken:e.channelToken,sender:e.sender,latitude:e.latitude,longitude:e.longitude,name:e.name,address:e.address},t)}async sendLocationRequest(e,t){return this.httpClient.post("/api/v1/whatsapp/send-location-request",{channelToken:e.channelToken,sender:e.sender,bodyText:e.bodyText,...e.headerText&&{headerText:e.headerText},...e.footerText&&{footerText:e.footerText}},t)}async sendCtaUrl(e,t){return this.httpClient.post("/api/v1/whatsapp/send-cta-url",{channelToken:e.channelToken,sender:e.sender,bodyText:e.bodyText,buttonText:e.buttonText,url:e.url,...e.header&&{header:e.header},...e.footerText&&{footerText:e.footerText}},t)}async sendMediaCarousel(e,t){return this.httpClient.post("/api/v1/whatsapp/send-media-carousel",{channelToken:e.channelToken,sender:e.sender,bodyText:e.bodyText,cards:e.cards},t)}async downloadMedia(e,t){return this.httpClient.post("/api/v1/whatsapp/download-media",{channelToken:e.channelToken,url:e.url},t)}};var g=class{constructor(e){this.httpClient=e;}async sendMessage(e,t){return this.httpClient.post("/api/v1/telegram/send-message",{channelToken:e.channelToken,chatId:e.chatId,text:e.text,parseMode:e.parseMode,replyToMessageId:e.replyToMessageId,disableNotification:e.disableNotification},t)}async sendMedia(e,t){return this.httpClient.post("/api/v1/telegram/send-media",{channelToken:e.channelToken,chatId:e.chatId,fileUrl:e.fileUrl,type:e.type,caption:e.caption,parseMode:e.parseMode,replyToMessageId:e.replyToMessageId},t)}async sendButtons(e,t){return this.httpClient.post("/api/v1/telegram/send-buttons",{channelToken:e.channelToken,chatId:e.chatId,text:e.text,buttons:e.buttons,parseMode:e.parseMode},t)}async sendLocation(e,t){return this.httpClient.post("/api/v1/telegram/send-location",{channelToken:e.channelToken,chatId:e.chatId,latitude:e.latitude,longitude:e.longitude,livePeriod:e.livePeriod},t)}async sendContact(e,t){return this.httpClient.post("/api/v1/telegram/send-contact",{channelToken:e.channelToken,chatId:e.chatId,phoneNumber:e.phoneNumber,firstName:e.firstName,lastName:e.lastName,vcard:e.vcard},t)}async sendPoll(e,t){return this.httpClient.post("/api/v1/telegram/send-poll",{channelToken:e.channelToken,chatId:e.chatId,question:e.question,options:e.options,isAnonymous:e.isAnonymous,type:e.type,correctOptionId:e.correctOptionId},t)}async sendVenue(e,t){return this.httpClient.post("/api/v1/telegram/send-venue",{channelToken:e.channelToken,chatId:e.chatId,latitude:e.latitude,longitude:e.longitude,title:e.title,address:e.address,foursquareId:e.foursquareId},t)}async sendDice(e,t){return this.httpClient.post("/api/v1/telegram/send-dice",{channelToken:e.channelToken,chatId:e.chatId,emoji:e.emoji},t)}async sendSticker(e,t){return this.httpClient.post("/api/v1/telegram/send-sticker",{channelToken:e.channelToken,chatId:e.chatId,stickerUrl:e.stickerUrl},t)}async sendVoice(e,t){return this.httpClient.post("/api/v1/telegram/send-voice",{channelToken:e.channelToken,chatId:e.chatId,voiceUrl:e.voiceUrl,caption:e.caption,duration:e.duration},t)}async sendVideoNote(e,t){return this.httpClient.post("/api/v1/telegram/send-video-note",{channelToken:e.channelToken,chatId:e.chatId,videoNoteUrl:e.videoNoteUrl,duration:e.duration,length:e.length},t)}async sendMediaGroup(e,t){return this.httpClient.post("/api/v1/telegram/send-media-group",{channelToken:e.channelToken,chatId:e.chatId,media:e.media},t)}async sendReplyKeyboard(e,t){return this.httpClient.post("/api/v1/telegram/send-reply-keyboard",{channelToken:e.channelToken,chatId:e.chatId,text:e.text,keyboard:e.keyboard,resizeKeyboard:e.resizeKeyboard,oneTimeKeyboard:e.oneTimeKeyboard},t)}async editMessage(e,t){return this.httpClient.post("/api/v1/telegram/edit-message",{channelToken:e.channelToken,chatId:e.chatId,messageId:e.messageId,text:e.text,parseMode:e.parseMode},t)}async deleteMessage(e,t){return this.httpClient.post("/api/v1/telegram/delete-message",{channelToken:e.channelToken,chatId:e.chatId,messageId:e.messageId},t)}async downloadMedia(e,t){return this.httpClient.post("/api/v1/telegram/download-media",{channelToken:e.channelToken,fileId:e.fileId},t)}};var u=class{constructor(e){this.httpClient=e;}async sendText(e,t){return this.httpClient.post("/api/v1/webchat/send-text",{channelToken:e.channelToken,chatId:e.chatId,type:"text",content:{text:e.messageText,typingTime:e.typingTime},typing:e.typing},t)}async sendMedia(e,t){return this.httpClient.post("/api/v1/webchat/send-media",{channelToken:e.channelToken,chatId:e.chatId,type:e.type,content:{url:e.fileUrl,caption:e.caption,typingTime:e.typingTime},typing:e.typing},t)}async sendCarousel(e,t){return this.httpClient.post("/api/v1/webchat/send-carousel",{channelToken:e.channelToken,chatId:e.chatId,type:"carousel",content:{cards:e.cards.map(n=>({title:n.title,subtitle:n.subtitle,imageUrl:n.imageUrl,buttons:n.buttons?.map(s=>({id:s.id||`btn_${Date.now()}_${Math.random()}`,text:s.text,type:s.type,value:s.value,url:s.url}))})),typingTime:e.typingTime},typing:e.typing},t)}async sendForm(e,t){return this.httpClient.post("/api/v1/webchat/send-form",{channelToken:e.channelToken,chatId:e.chatId,type:"form",content:{id:e.id,title:e.title,submitText:e.submitButtonText,fields:e.fields.map(n=>({id:n.id||n.name,type:n.type,label:n.label,placeholder:n.placeholder,required:n.required,options:n.options})),typingTime:e.typingTime},typing:e.typing},t)}async sendQuickReplies(e,t){return this.httpClient.post("/api/v1/webchat/send-quick-replies",{channelToken:e.channelToken,chatId:e.chatId,type:"quickReplies",content:{text:e.messageText,quickReplies:e.quickReplies.map(n=>({id:n.id||`qr_${Date.now()}_${Math.random()}`,text:n.text,value:n.value})),typingTime:e.typingTime},typing:e.typing},t)}async sendCard(e,t){return this.httpClient.post("/api/v1/webchat/send-card",{channelToken:e.channelToken,chatId:e.chatId,type:"card",content:{title:e.title,subtitle:e.description,imageUrl:e.imageUrl,buttons:e.buttons?.map(n=>({id:n.id||`btn_${Date.now()}_${Math.random()}`,text:n.text,type:n.type,value:n.value,url:n.url})),typingTime:e.typingTime},typing:e.typing},t)}async sendButtons(e,t){return this.httpClient.post("/api/v1/webchat/send-buttons",{channelToken:e.channelToken,chatId:e.chatId,type:"buttons",content:{text:e.messageText,buttons:e.buttons.map(n=>({id:n.id||`btn_${Date.now()}_${Math.random()}`,text:n.text,type:n.type,value:n.value,url:n.url})),typingTime:e.typingTime},typing:e.typing},t)}};var m=class{constructor(e){this.httpClient=e;}async listPosts(e,t){return this.httpClient.post("/api/v1/facebook/list-posts",{channelToken:e.channelToken,channelType:e.channelType,limit:e.limit,after:e.after,type:e.type,includeComments:e.includeComments,includeReactions:e.includeReactions},t)}async listComments(e,t){return this.httpClient.post("/api/v1/facebook/list-comments",{channelToken:e.channelToken,channelType:e.channelType,postId:e.postId,limit:e.limit,after:e.after,order:e.order,filterUnanswered:e.filterUnanswered,includeReplies:e.includeReplies},t)}async createPost(e,t){return this.httpClient.post("/api/v1/facebook/create-post",{channelToken:e.channelToken,pageId:e.pageId,message:e.message,link:e.link},t)}async replyComment(e,t){return this.httpClient.post("/api/v1/facebook/reply-comment",{channelToken:e.channelToken,commentId:e.commentId,message:e.message},t)}async deleteComment(e,t){return this.httpClient.post("/api/v1/facebook/delete-comment",{channelToken:e.channelToken,commentId:e.commentId},t)}async sendText(e,t){return this.httpClient.post("/api/v1/facebook/send-text",{channelToken:e.channelToken,recipientId:e.recipientId,message:e.message},t)}async sendMedia(e,t){return this.httpClient.post("/api/v1/facebook/send-media",{channelToken:e.channelToken,recipientId:e.recipientId,fileUrl:e.fileUrl,type:e.type,caption:e.caption},t)}async sendButtons(e,t){return this.httpClient.post("/api/v1/facebook/send-buttons",{channelToken:e.channelToken,recipientId:e.recipientId,message:e.message,buttons:e.buttons},t)}async sendSticker(e,t){return this.httpClient.post("/api/v1/facebook/send-sticker",{channelToken:e.channelToken,recipientId:e.recipientId,stickerId:e.stickerId},t)}async replyMessage(e,t){return this.httpClient.post("/api/v1/facebook/reply-message",{channelToken:e.channelToken,messageId:e.messageId,message:e.message},t)}async replyMedia(e,t){return this.httpClient.post("/api/v1/facebook/reply-media",{channelToken:e.channelToken,messageId:e.messageId,fileUrl:e.fileUrl,type:e.type,caption:e.caption},t)}async sharePost(e,t){return this.httpClient.post("/api/v1/facebook/share-post",{channelToken:e.channelToken,mediaId:e.mediaId,recipientId:e.recipientId},t)}async getUserProfile(e,t){return this.httpClient.post("/api/v1/facebook/user-profile",{channelToken:e.channelToken,userId:e.userId},t)}async getPageProfile(e,t){return this.httpClient.post("/api/v1/facebook/page-profile",{channelToken:e.channelToken,pageId:e.pageId},t)}async downloadMedia(e,t){return this.httpClient.post("/api/v1/facebook/download-media",{channelToken:e.channelToken,url:e.url},t)}};var T=class{constructor(e){this.httpClient=e;}async sendPrivateReply(e,t){return this.httpClient.post("/api/v1/instagram/private-reply",{channelToken:e.channelToken,commentId:e.commentId,message:e.message},t)}async sendText(e,t){return this.httpClient.post("/api/v1/instagram/messages/text",{channelToken:e.channelToken,recipientId:e.recipientId,text:e.text,...e.tags&&{tags:e.tags}},t)}async sendMedia(e,t){return this.httpClient.post("/api/v1/instagram/messages/media",{channelToken:e.channelToken,recipientId:e.recipientId,attachment:e.attachment,...e.tags&&{tags:e.tags}},t)}async sendImages(e,t){return this.httpClient.post("/api/v1/instagram/messages/images",{channelToken:e.channelToken,recipientId:e.recipientId,images:e.images},t)}async sendSticker(e,t){return this.httpClient.post("/api/v1/instagram/messages/sticker",{channelToken:e.channelToken,recipientId:e.recipientId,stickerType:e.stickerType},t)}async reactMessage(e,t){return this.httpClient.post("/api/v1/instagram/messages/reaction",{channelToken:e.channelToken,messageId:e.messageId,reactionType:e.reactionType},t)}async removeReaction(e,t){return this.httpClient.delete("/api/v1/instagram/messages/reaction",t,{channelToken:e.channelToken,recipientId:e.recipientId,messageId:e.messageId})}async sendQuickReplies(e,t){return this.httpClient.post("/api/v1/instagram/messages/quick-replies",{channelToken:e.channelToken,recipientId:e.recipientId,message:e.message,quickReplies:e.quickReplies},t)}async sendGenericTemplate(e,t){return this.httpClient.post("/api/v1/instagram/messages/generic-template",{channelToken:e.channelToken,recipientId:e.recipientId,elements:e.elements},t)}async sendButtonTemplate(e,t){return this.httpClient.post("/api/v1/instagram/messages/button-template",{channelToken:e.channelToken,recipientId:e.recipientId,text:e.text,buttons:e.buttons},t)}async sendSenderAction(e,t){return this.httpClient.post("/api/v1/instagram/messages/sender-action",{channelToken:e.channelToken,recipientId:e.recipientId,action:e.action},t)}async getUserProfile(e,t){return this.httpClient.post("/api/v1/instagram/user-profile",{channelToken:e.channelToken,userId:e.userId},t)}async listPosts(e,t){return this.httpClient.post("/api/v1/instagram/posts",{channelToken:e.channelToken,userId:e.userId,limit:e.limit},t)}async getBusinessProfile(e,t){return this.httpClient.post("/api/v1/instagram/business-profile",{channelToken:e.channelToken},t)}async downloadMedia(e,t){return this.httpClient.post("/api/v1/instagram/download-media",{channelToken:e.channelToken,url:e.url},t)}async createMediaContainer(e,t){return this.httpClient.post("/api/v1/instagram/media",{channelToken:e.channelToken,image_url:e.image_url,video_url:e.video_url,media_type:e.media_type,caption:e.caption,is_carousel_item:e.is_carousel_item,children:e.children,upload_type:e.upload_type,trial_params:e.trial_params,alt_text:e.alt_text,location_id:e.location_id,product_tags:e.product_tags,user_tags:e.user_tags},t)}async publishMedia(e,t){return this.httpClient.post("/api/v1/instagram/media_publish",{channelToken:e.channelToken,creation_id:e.creation_id},t)}async getContainerStatus(e,t){return this.httpClient.post(`/api/v1/instagram/media/${e.container_id}/status`,{channelToken:e.channelToken},t)}async getPublishingLimit(e,t){return this.httpClient.post("/api/v1/instagram/content_publishing_limit",{channelToken:e.channelToken},t)}async uploadVideo(e,t){return this.httpClient.post("/api/v1/instagram/upload",{channelToken:e.channelToken,container_id:e.container_id,file_url:e.file_url,offset:e.offset,file_size:e.file_size},t)}};var k=class{constructor(e){this.httpClient=new l(e),this.auth=new d(this.httpClient),this.channels=new c(this.httpClient),this.integrations=new h(this.httpClient),this.whatsapp=new p(this.httpClient),this.telegram=new g(this.httpClient),this.webchat=new u(this.httpClient),this.facebook=new m(this.httpClient),this.instagram=new T(this.httpClient);}},K=k;
7
7
  exports.OficialAPISDK=k;exports.default=K;//# sourceMappingURL=index.js.map
8
8
  //# sourceMappingURL=index.js.map