opensips-js 0.1.48 → 0.1.50

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/index.d.ts CHANGED
@@ -604,6 +604,8 @@ export declare const MSRP_EVT: {
604
604
  readonly MESSAGE: "m.conversation.message";
605
605
  readonly MEMBER: "m.conversation.member";
606
606
  readonly CLOSED: "m.conversation.closed";
607
+ readonly REOPEN: "m.conversation.reopen";
608
+ readonly DELETE: "m.conversation.delete";
607
609
  readonly SYNC: "m.sync";
608
610
  readonly UPLOAD_REQUEST: "m.upload.request";
609
611
  readonly UPLOAD_RESPONSE: "m.upload.response";
@@ -611,27 +613,48 @@ export declare const MSRP_EVT: {
611
613
  readonly FILE_ACCESS_RESPONSE: "m.file.access.response";
612
614
  readonly REACTION: "m.reaction";
613
615
  readonly TYPING: "m.typing";
616
+ readonly PRESENCE: "m.presence";
614
617
  readonly SENT: "m.sent";
615
618
  readonly DELIVERED: "m.delivered";
616
619
  readonly READ: "m.read";
620
+ readonly UNREAD: "m.unread";
617
621
  readonly FAILED: "m.failed";
618
622
  readonly SENDING: "m.sending";
619
623
  };
620
624
 
621
625
  declare type msrpConversationCreatedListener = (payload: {
622
- conversationKey: string
623
626
  conversation: MSRPConversationState_2
624
627
  }) => void
625
628
 
626
- declare type msrpConversationRemovedListener = (payload: { conversationKey: string }) => void
629
+ /**
630
+ * A conversation is addressed exclusively by its public numeric
631
+ * `conversation_id`. A stringified id is also accepted for convenience.
632
+ */
633
+ export declare type MSRPConversationRef = number | string;
634
+
635
+ declare type msrpConversationRemovedListener = (payload: {
636
+ conversation_id?: number
637
+ }) => void
627
638
 
628
639
  export declare interface MSRPConversationState {
629
- conversationKey: string
640
+ /**
641
+ * Public, stable numeric conversation identifier assigned by the backend.
642
+ * This is the only identifier exposed to application code — conversations
643
+ * are addressed exclusively by `conversation_id`.
644
+ */
645
+ conversation_id?: number
630
646
  creator: string | null
631
647
  members: Set<string>
632
648
  memberRoles: Map<string, MSRPMemberRole>
633
649
  currentUserRole: MSRPMemberRole
634
650
  currentUserStatus: MSRPMembership | null
651
+ /**
652
+ * Per-user read pointer (backend `last_read_message_id` in the current
653
+ * user's member state). `null` means the whole conversation is unread;
654
+ * an event_id means everything after that event is unread. Consumers
655
+ * derive the unread count from this pointer + the local timeline.
656
+ */
657
+ currentUserLastReadMessageId?: string | null
635
658
  state_events: { [key: string]: { [stateKey: string]: any } }
636
659
  created_at: number
637
660
  updated_at: number
@@ -639,12 +662,24 @@ export declare interface MSRPConversationState {
639
662
  }
640
663
 
641
664
  declare interface MSRPConversationState_2 {
642
- conversationKey: string
665
+ /**
666
+ * Public, stable numeric conversation identifier assigned by the backend.
667
+ * This is the only identifier exposed to application code — conversations
668
+ * are addressed exclusively by `conversation_id`.
669
+ */
670
+ conversation_id?: number
643
671
  creator: string | null
644
672
  members: Set<string>
645
673
  memberRoles: Map<string, MSRPMemberRole_2>
646
674
  currentUserRole: MSRPMemberRole_2
647
675
  currentUserStatus: MSRPMembership_2 | null
676
+ /**
677
+ * Per-user read pointer (backend `last_read_message_id` in the current
678
+ * user's member state). `null` means the whole conversation is unread;
679
+ * an event_id means everything after that event is unread. Consumers
680
+ * derive the unread count from this pointer + the local timeline.
681
+ */
682
+ currentUserLastReadMessageId?: string | null
648
683
  state_events: { [key: string]: { [stateKey: string]: any } }
649
684
  created_at: number
650
685
  updated_at: number
@@ -652,11 +687,11 @@ declare interface MSRPConversationState_2 {
652
687
  }
653
688
 
654
689
  declare type msrpConversationUpdatedListener = (payload: {
655
- conversationKey: string
690
+ conversation_id?: number
656
691
  patch: Partial<MSRPConversationState_2>
657
692
  }) => void
658
693
 
659
- declare type MSRPInitializingListener = (sessionId: string | undefined) => void
694
+ declare type MSRPInitializingListener = (value: boolean) => void
660
695
 
661
696
  export declare type MSRPMemberRole = 'in_charge' | 'manager' | 'assigned'
662
697
 
@@ -682,10 +717,25 @@ declare class MSRPMessage {
682
717
  }
683
718
 
684
719
  declare type msrpMessageAddedListener = (payload: {
685
- conversationKey: string
720
+ conversation_id?: number
686
721
  message: any
687
722
  }) => void
688
723
 
724
+ declare type msrpMessageDeletedListener = (payload: {
725
+ conversation_id?: number
726
+ eventId: string
727
+ deletedBy: string
728
+ updatedAt: number
729
+ }) => void
730
+
731
+ declare type msrpMessageEditedListener = (payload: {
732
+ conversation_id?: number
733
+ eventId: string
734
+ newContent: any
735
+ editEvent: any
736
+ updatedAt: number
737
+ }) => void
738
+
689
739
  export declare type MSRPMessageEventType = {
690
740
  message: MSRPMessage,
691
741
  session: MSRPSessionExtended_2
@@ -708,7 +758,7 @@ declare class MSRPModule {
708
758
  private uploadRequestTimeoutMs;
709
759
  private fileAccessTimeoutMs;
710
760
  private typingKeepAliveInterval;
711
- private typingKeepAliveConversationKey;
761
+ private typingKeepAliveConversationId;
712
762
  private typingKeepAliveIntervalMs;
713
763
  constructor(context: any);
714
764
  get isMSRPInitializing(): boolean;
@@ -739,55 +789,101 @@ declare class MSRPModule {
739
789
  safeSendMSRP(body: string): boolean;
740
790
  private buildCreateConversationEvent;
741
791
  private buildTextMessageEvent;
792
+ private buildEditMessageEvent;
793
+ private buildDeleteMessageEvent;
742
794
  private buildMediaMessageEvent;
743
795
  private buildMemberEvent;
744
796
  private buildCloseConversationEvent;
745
797
  private buildReactionEvent;
746
798
  private buildTypingEvent;
747
799
  private buildReadReceiptEvent;
800
+ private buildUnreadEvent;
748
801
  sendCreateConversationMessage(targetSip: string | string[]): boolean;
749
- sendTextMessage(conversationKey: string, text: string): boolean;
750
- sendMediaMessage(conversationKey: string, uploadResult: MSRPUploadResult, caption?: string): boolean;
751
- sendReaction(conversationKey: string, targetEventId: string, emoji: string): boolean;
752
- sendTypingIndicator(conversationKey: string, isTyping: boolean): boolean;
753
- startTypingKeepAlive(conversationKey: string): void;
754
- stopTypingKeepAlive(sendStop?: boolean): void;
755
- sendReadReceipt(conversationKey: string, lastEventId: string): boolean;
802
+ sendTextMessage(conversationRef: MSRPConversationRef, text: string, options?: MSRPSendMessageOptions): boolean;
803
+ /**
804
+ * Send an internal note — a message only visible to operators. The backend
805
+ * fan-out layer skips WhatsApp/SMS members when
806
+ * `content.message_type === 'internal_note'`, so it is never delivered to
807
+ * the customer channel.
808
+ */
809
+ sendInternalNote(conversationRef: MSRPConversationRef, text: string, options?: Omit<MSRPSendMessageOptions, 'messageType'>): boolean;
810
+ /**
811
+ * Edit a previously sent message. Only the original author may edit, and
812
+ * only within the per-channel edit window enforced by the backend.
813
+ */
814
+ editMessage(conversationRef: MSRPConversationRef, targetEventId: string, newText: string): boolean;
815
+ /**
816
+ * Soft-delete a message ("delete for everyone"). Only the original author
817
+ * may delete; the backend marks it `is_deleted` and fans out the deletion.
818
+ */
819
+ deleteMessage(conversationRef: MSRPConversationRef, targetEventId: string): boolean;
820
+ /**
821
+ * Forward the text of an existing message into another conversation.
822
+ * The caller owns `forwardedFromLabel`; when omitted the raw sender URI
823
+ * of the source message is used. The SDK never invents a display name.
824
+ */
825
+ forwardMessage(sourceMessage: any, targetConversationRef: MSRPConversationRef, forwardedFromLabel?: string): boolean;
826
+ sendMediaMessage(conversationRef: MSRPConversationRef, uploadResult: MSRPUploadResult, caption?: string): boolean;
827
+ sendReaction(conversationRef: MSRPConversationRef, targetEventId: string, emoji: string, action?: MSRPReactionAction): boolean;
828
+ /** Convenience wrapper to remove a previously added reaction. */
829
+ removeReaction(conversationRef: MSRPConversationRef, targetEventId: string, emoji: string): boolean;
830
+ /**
831
+ * Emit a single `m.typing` heartbeat. Prefer {@link startTypingKeepAlive}
832
+ * — the heartbeat protocol requires a stream of `true` events.
833
+ */
834
+ sendTypingIndicator(conversationRef: MSRPConversationRef): boolean;
835
+ startTypingKeepAlive(conversationRef: MSRPConversationRef): void;
836
+ /**
837
+ * Stop our own heartbeat stream. Does NOT send a `typing=false` event —
838
+ * peers clear our indicator via their own silence-timeout, which also
839
+ * covers crash / network-drop / session-end cases.
840
+ */
841
+ stopTypingKeepAlive(): void;
842
+ sendReadReceipt(conversationRef: MSRPConversationRef, lastEventId: string): boolean;
843
+ /**
844
+ * Set the caller's per-user read pointer.
845
+ * - `lastReadEventId` = the last event to remain read (everything after
846
+ * becomes unread).
847
+ * - `null` (or omitted) = mark the whole conversation as unread.
848
+ */
849
+ markAsUnread(conversationRef: MSRPConversationRef, lastReadEventId?: string | null): boolean;
756
850
  /**
757
851
  * Close a conversation. Only callers with role 'in_charge' or 'manager'
758
852
  * are allowed by the backend.
759
853
  */
760
- closeConversation(conversationKey: string, reason?: string, cause?: string): boolean;
854
+ closeConversation(conversationRef: MSRPConversationRef, reason?: string, cause?: string): boolean;
761
855
  /**
762
- * Change another member's role inside a conversation. The current user
763
- * must be 'in_charge' or 'manager'.
856
+ * Change another member's role. Only callers with role 'in_charge' or
857
+ * 'manager' are allowed by the backend.
764
858
  */
765
- changeMemberRole(conversationKey: string, targetUri: string, newRole: MSRPMemberRole): boolean;
766
- acceptInvite(conversationKey: string): boolean;
767
- rejectInvite(conversationKey: string): boolean;
768
- leaveConversation(conversationKey: string): boolean;
859
+ changeMemberRole(conversationRef: MSRPConversationRef, targetUri: string, newRole: MSRPMemberRole): boolean;
860
+ acceptInvite(conversationRef: MSRPConversationRef): boolean;
861
+ rejectInvite(conversationRef: MSRPConversationRef): boolean;
862
+ leaveConversation(conversationRef: MSRPConversationRef): boolean;
769
863
  /**
770
- * Ask the server for a presigned upload URL via MSRP. Resolves with the
771
- * upload metadata once the matching `m.upload.response` arrives, or
772
- * rejects after `uploadRequestTimeoutMs` if no response is received.
864
+ * Ask the server for a presigned upload URL. Resolves with the upload
865
+ * metadata once the matching `m.upload.response` arrives, or rejects
866
+ * after `uploadRequestTimeoutMs`.
773
867
  */
774
- requestUploadUrl(conversationKey: string, filename: string, mimeType: string, fileSize: number): Promise<MSRPUploadResult>;
868
+ requestUploadUrl(conversationRef: MSRPConversationRef, filename: string, mimeType: string, fileSize: number): Promise<MSRPUploadResult>;
775
869
  /**
776
- * Ask the server for a one-shot download URL for a previously-uploaded
777
- * file. Resolves with the download URL, rejects on timeout or explicit
778
- * server error.
870
+ * Ask the server for a one-shot download URL. Resolves with the URL,
871
+ * rejects on timeout or explicit server error.
779
872
  */
780
- requestFileAccess(conversationKey: string, eventId: string): Promise<string>;
873
+ requestFileAccess(conversationRef: MSRPConversationRef, eventId: string): Promise<string>;
781
874
  /**
782
875
  * High-level helper: request a presigned URL, POST the file to it, then
783
876
  * send the resulting media message into the conversation in one go.
784
877
  */
785
- uploadFile(conversationKey: string, file: File, caption?: string): Promise<MSRPUploadResult>;
878
+ uploadFile(conversationRef: MSRPConversationRef, file: File, caption?: string): Promise<MSRPUploadResult>;
786
879
  private processIncomingMSRPMessage;
787
880
  private handleIncomingEvent;
788
881
  private handleIncomingSync;
789
882
  private handleIncomingConversationCreate;
790
883
  private handleIncomingConversationMessage;
884
+ private handleIncomingMessageDelete;
885
+ private handleIncomingConversationReopen;
886
+ private handleIncomingPresence;
791
887
  private handleIncomingConversationClosed;
792
888
  private handleIncomingReceipt;
793
889
  private handleIncomingTyping;
@@ -796,11 +892,14 @@ declare class MSRPModule {
796
892
  private handleIncomingUploadResponse;
797
893
  private handleIncomingFileAccessResponse;
798
894
  private upsertConversationState;
895
+ private toConversationId;
896
+ private sendEvent;
799
897
  private snapshotConversation;
800
898
  private snapshotConversationsMap;
801
899
  isConversationClosed(conversation: MSRPConversationState | undefined | null): boolean;
802
- private conversationKeyOf;
900
+ private conversationIdOf;
803
901
  extractSipUser(sipUri: string | null | undefined): string | null;
902
+ private readLastReadEventIdFromMemberContent;
804
903
  extractDisplayName(uri: string | null | undefined): string;
805
904
  }
806
905
 
@@ -820,8 +919,18 @@ declare interface MSRPOptions_2 extends AnswerOptions {
820
919
  fromDisplayName?: string;
821
920
  }
822
921
 
922
+ declare type msrpPresenceListener = (payload: {
923
+ conversation_id?: number
924
+ sender: string
925
+ presence: string | null
926
+ lastActiveAt: number | null
927
+ updatedAt: number
928
+ }) => void
929
+
930
+ export declare type MSRPReactionAction = 'add' | 'remove';
931
+
823
932
  declare type msrpReactionChangedListener = (payload: {
824
- conversationKey: string
933
+ conversation_id?: number
825
934
  eventId: string
826
935
  emoji: string
827
936
  action: 'add' | 'remove'
@@ -830,12 +939,22 @@ declare type msrpReactionChangedListener = (payload: {
830
939
  }) => void
831
940
 
832
941
  declare type msrpReceiptChangedListener = (payload: {
833
- conversationKey: string
942
+ conversation_id?: number
834
943
  eventId: string
835
944
  status: MSRPMessageStatus_2
836
945
  updatedAt: number
837
946
  }) => void
838
947
 
948
+ /** Optional modifiers for an outgoing text/note message. */
949
+ export declare interface MSRPSendMessageOptions {
950
+ /** event_id of the message being replied to — becomes `content.in_reply_to`. */
951
+ replyToEventId?: string;
952
+ /** Overrides `content.message_type` (defaults to 'text'). */
953
+ messageType?: string;
954
+ /** Attribution label for a forwarded message — becomes `content.forwarded_from`. */
955
+ forwardedFrom?: string;
956
+ }
957
+
839
958
  declare class MSRPSession extends EventEmitter {
840
959
  _ua: UAExtendedInterface
841
960
  id: any
@@ -1034,7 +1153,7 @@ declare type msrpSyncCompletedListener = (payload: {
1034
1153
  }) => void
1035
1154
 
1036
1155
  declare type msrpTypingListener = (payload: {
1037
- conversationKey: string
1156
+ conversation_id?: number
1038
1157
  sender: string
1039
1158
  isTyping: boolean
1040
1159
  }) => void
@@ -1120,6 +1239,9 @@ export declare interface OpenSIPSEventMap extends UAEventMap {
1120
1239
  msrpReceiptChanged: msrpReceiptChangedListener
1121
1240
  msrpReactionChanged: msrpReactionChangedListener
1122
1241
  msrpTyping: msrpTypingListener
1242
+ msrpMessageEdited: msrpMessageEditedListener
1243
+ msrpMessageDeleted: msrpMessageDeletedListener
1244
+ msrpPresence: msrpPresenceListener
1123
1245
  // JANUS
1124
1246
  conferenceStart: conferenceStartListener
1125
1247
  conferenceEnd: conferenceEndListener