File tree 5 files changed +112
-0
lines changed
5 files changed +112
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { env } from 'bun'
2
+ import { Kient } from 'kient'
3
+
4
+ const kient = new Kient ( )
5
+ kient . setAuthToken ( env . KICK_TOKEN as string )
6
+
7
+ const bot = await kient . api . chat . send ( {
8
+ type : 'bot' ,
9
+ message : 'Message will be send to authenticated user channel' ,
10
+ } )
11
+ console . log ( bot . raw )
12
+
13
+ const user = await kient . api . chat . send ( {
14
+ type : 'user' ,
15
+ message : 'Message will be send to specified user id' ,
16
+ userId : 0 ,
17
+ } )
18
+ console . log ( user . raw )
Original file line number Diff line number Diff line change
1
+ import { APIBase } from '../api-base'
2
+ import { sendChat , type SendChatParams } from './send-chat'
3
+
4
+ /**
5
+ * Description placeholder
6
+ *
7
+ * @group APIs
8
+ */
9
+ export class ChatAPI extends APIBase {
10
+ /**
11
+ * Send a chat to a channel and returns the status of the message
12
+ *
13
+ * @param query Accepts and object of the message and how if it's being sent from a bot account
14
+ */
15
+ send ( params : SendChatParams ) {
16
+ return sendChat ( this . kient , params )
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+ import type { Kient } from 'kient'
2
+ import type { APIResponse } from '../../util/api-response'
3
+ import { Chat , type ChatData } from '../../structures/chat'
4
+
5
+ interface SendBotChatParams {
6
+ message : string
7
+ type : 'bot'
8
+ }
9
+
10
+ interface SendUserChatParams {
11
+ message : string
12
+ type : 'user'
13
+ /**
14
+ * The target channel's user ID to send the message to
15
+ */
16
+ userId : number
17
+ }
18
+
19
+ export type SendChatParams = SendUserChatParams | SendBotChatParams
20
+
21
+ export async function sendChat ( kient : Kient , params : SendChatParams ) {
22
+ const requestParams : {
23
+ content : string
24
+ type : 'user' | 'bot'
25
+ broadcaster_user_id ?: number
26
+ } = {
27
+ content : params . message ,
28
+ type : params . type ,
29
+ }
30
+
31
+ if ( params . type === 'user' ) {
32
+ requestParams . broadcaster_user_id = params . userId
33
+ }
34
+
35
+ const response = await kient . _apiClient . fetch < APIResponse < ChatData > > ( '/chat' , {
36
+ method : 'POST' ,
37
+ body : JSON . stringify ( requestParams ) ,
38
+ } )
39
+
40
+ const chat = new Chat ( kient , response . data )
41
+ return chat
42
+ }
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { WSClient, type WSClientOptions } from './ws.client'
6
6
import { CategoryAPI } from './api/category'
7
7
import { UserAPI } from './api/user'
8
8
import { ChannelAPI } from './api/channel'
9
+ import { ChatAPI } from './api/chat'
9
10
10
11
type DeepPartial < T > = T extends object ? { [ P in keyof T ] ?: DeepPartial < T [ P ] > } : T
11
12
@@ -58,5 +59,6 @@ export class Kient extends EventEmitter<KientEventEmitters> {
58
59
category : new CategoryAPI ( this ) ,
59
60
user : new UserAPI ( this ) ,
60
61
channel : new ChannelAPI ( this ) ,
62
+ chat : new ChatAPI ( this ) ,
61
63
}
62
64
}
Original file line number Diff line number Diff line change
1
+ import type { Kient } from '../kient'
2
+ import { Base } from './base'
3
+
4
+ export interface ChatData {
5
+ is_sent : boolean
6
+ message_id : string
7
+ }
8
+
9
+ /**
10
+ * Data structure of a chat message
11
+ *
12
+ * @group API Structures
13
+ */
14
+ export class Chat extends Base < ChatData > {
15
+ /**
16
+ * The id of the sent message
17
+ */
18
+ id : string
19
+
20
+ /**
21
+ * A boolean indicating if the message has been sent
22
+ */
23
+ isSent : boolean
24
+
25
+ /** @internal */
26
+ constructor ( kient : Kient , data : ChatData ) {
27
+ super ( kient , data )
28
+
29
+ this . id = data . message_id
30
+ this . isSent = data . is_sent
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments