Skip to content

Instantly share code, notes, and snippets.

@bwyx
Created May 18, 2024 09:20
Show Gist options
  • Select an option

  • Save bwyx/358c8aeadb3f65f78cbea2e6246ea5cb to your computer and use it in GitHub Desktop.

Select an option

Save bwyx/358c8aeadb3f65f78cbea2e6246ea5cb to your computer and use it in GitHub Desktop.
qiscus-sdk-core@^2 uncompleted type definitions
// qiscus-sdk-core@^2 uncompleted type definitions
declare module 'qiscus-sdk-core' {
interface InitOptions {
AppId: string
options?: {
baseUrl?: string
[key: string]: unknown
}
}
export default class QiscusSDK {
constructor()
isLogin: boolean
selected?: {
id: number
comments: Selected_RawComment[]
}
init: (opts: InitOptions) => Promise<void>
setUser: (
userId: string,
userKey: string,
username: string,
avatarURL?: string,
extras?: Record<string, string | number | boolean>
) => Promise<void>
setUserWithIdentityToken: (identityToken: string) => void
disconnect(): void
getOrCreateRoomByChannel: (channelId: number) => Promise<unknown>
getNonce(): Promise<{ expired_at: number; nonce: string }>
loadComments: (
roomId: string | number,
opts?: { last_comment_id?: number; after?: boolean; limit?: number }
) => Promise<LoadComments_RawComment[]>
chatGroup: (roomId: string | number) => Promise<void>
sendComment: (
roomId: string | number,
message: string,
messageId?: string | null,
type?: CommentType,
payload?: string
) => Promise<Sent_RawComment>
verifyIdentityToken: (identityToken: string) => Promise<string>
upload(file: File, callback?: ProgressListener): void
userData: User | null;
[key: string]: unknown
}
// typings
export type ProgressListener = (
error?: Error,
progress?: number,
url?: string
) => void
export type RoomType = 'single' | 'group' | 'channel'
export type CommentType =
| 'text'
| 'file_attachment'
| 'custom'
| 'system_event'
| 'buttons'
| 'button_postback_response'
export type CommentStatus =
| 'sending'
| 'pending'
| 'sent'
| 'delivered'
| 'read'
| 'failed'
export type CommentPayload = Record<string, unknown>
export interface BaseRawComment {
id: number
email: string
user_extras: Record<string, string>
message: string
timestamp: string
unix_timestamp: number
unix_nano_timestamp: bigint
unique_temp_id: string
type: CommentType
status: CommentStatus
payload: CommentPayload
extras: Record<string, string>
room_id: number
}
export interface Sent_RawComment extends BaseRawComment {
// id: 1595714895
before_id: number // 1595692044
// message: 'p'
username_as: string // '1'
username_real: string // '1'
// email: '1'
// user_extras: {
// additional_extras: null
// is_customer: true
// type: 'customer'
// }
date: string // '2023-09-14'
time: string // '11:46'
// timestamp: '2023-09-14T04:46:58Z'
unique_id: string // 'bq1694666814964'
// unique_temp_id: 'bq1694666814964'
// room_id: 174089019
// unix_timestamp: 1694666818
// unix_nano_timestamp: 1694666818892790000
// extras: {}
is_deleted: boolean // false
isPending: boolean // false
isFailed: boolean // false
isDelivered: boolean // false
isRead: boolean // false
isSent: boolean // true
attachment: null
// payload: {}
// status: 'sent'
// type: 'text'
subtype: null
comment_before_id: number // 1595692044
comment_before_id_str: string // '1595692044'
disable_link_preview: boolean // false
id_str: string // '1595714895'
is_public_channel: boolean // false
room_avatar: string // 'https://d1edrlpyc25xu0.cloudfront.net/kiwari-prod/image/upload/wMWsDZP6ta/1516689726-ic_qiscus_client.png'
room_id_str: string // '174089019'
room_name: string // '1'
room_type: string // 'group'
topic_id: number // 174089019
topic_id_str: string // '174089019'
user_avatar: {
avatar: {
url: string // 'https://d1edrlpyc25xu0.cloudfront.net/kiwari-prod/image/upload/wMWsDZP6ta/1516689726-ic_qiscus_client.png'
}
}
user_avatar_url: string // 'https://d1edrlpyc25xu0.cloudfront.net/kiwari-prod/image/upload/wMWsDZP6ta/1516689726-ic_qiscus_client.png'
user_id: number // 1809418921
user_id_str: string // '1809418921'
username: string // '1'
}
export interface Selected_RawComment extends BaseRawComment {
// id: number
before_id: number
// message: string
username_as: string
username_real: string
// email: string
// user_extras: {
// additional_extras: null
// is_customer: true
// type: 'customer'
// }
date: string // '2023-09-13'
time: string // '14:54'
// timestamp: string // '2023-09-13T07:54:51Z'
unique_id: string // 'bq1694591688298'
// unique_temp_id: string // 'bq1694591688298'
avatar: string
// room_id: number
isChannel: boolean
// unix_timestamp: number
// unix_nano_timestamp: number
// extras: object
is_deleted: boolean
isPending: boolean
isFailed: boolean
isDelivered: boolean
isRead: boolean
isSent: boolean
attachment: null
// payload: CommentPayload
// status: CommentStatus
// type: CommentType
subtype: null
}
export interface LoadComments_RawComment extends BaseRawComment {
id_str: string
comment_before_id: number
comment_before_id_str: string
username: string
user_id: number
user_id_str: string
user_avatar_url: string
user_avatar: {
avatar: {
url: string
}
}
room_avatar: string
room_id_str: string
room_name: string
room_type: RoomType
topic_id: number
topic_id_str: string
is_public_channel: boolean
disable_link_preview: boolean
}
export interface NewMessagesCallback_RawComment
extends Omit<LoadComments_RawComment, 'user_avatar'> {
app_code: string
chat_type: string
user_avatar: string
created_at: string
raw_room_name: string
room_options: string
}
export interface User {
active: boolean
app: {
code: string
id: number
id_str: string
name: string
}
avatar: {
avatar: {
url: string
}
}
avatar_url: string
email: string
extras: {
additional_extras: null
is_customer: boolean
type: string
}
id: number
id_str: string
last_comment_id: number
last_comment_id_str: string
last_sync_event_id: number
pn_android_configured: boolean
pn_ios_configured: boolean
rtKey: string
token: string
username: string
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment