-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4c7794
commit 0f9d0e2
Showing
5 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { env } from 'bun' | ||
import { Kient } from 'kient' | ||
|
||
const kient = new Kient() | ||
kient.setAuthToken(env.KICK_TOKEN as string) | ||
|
||
const bot = await kient.api.chat.send({ | ||
type: 'bot', | ||
message: 'Message will be send to authenticated user channel', | ||
}) | ||
console.log(bot.raw) | ||
|
||
const user = await kient.api.chat.send({ | ||
type: 'user', | ||
message: 'Message will be send to specified user id', | ||
userId: 0, | ||
}) | ||
console.log(user.raw) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { APIBase } from '../api-base' | ||
import { sendChat, type SendChatParams } from './send-chat' | ||
|
||
/** | ||
* Description placeholder | ||
* | ||
* @group APIs | ||
*/ | ||
export class ChatAPI extends APIBase { | ||
/** | ||
* Send a chat to a channel and returns the status of the message | ||
* | ||
* @param query Accepts and object of the message and how if it's being sent from a bot account | ||
*/ | ||
send(params: SendChatParams) { | ||
return sendChat(this.kient, params) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { Kient } from 'kient' | ||
import type { APIResponse } from '../../util/api-response' | ||
import { Chat, type ChatData } from '../../structures/chat' | ||
|
||
interface SendBotChatParams { | ||
message: string | ||
type: 'bot' | ||
} | ||
|
||
interface SendUserChatParams { | ||
message: string | ||
type: 'user' | ||
/** | ||
* The target channel's user ID to send the message to | ||
*/ | ||
userId: number | ||
} | ||
|
||
export type SendChatParams = SendUserChatParams | SendBotChatParams | ||
|
||
export async function sendChat(kient: Kient, params: SendChatParams) { | ||
const requestParams: { | ||
content: string | ||
type: 'user' | 'bot' | ||
broadcaster_user_id?: number | ||
} = { | ||
content: params.message, | ||
type: params.type, | ||
} | ||
|
||
if (params.type === 'user') { | ||
requestParams.broadcaster_user_id = params.userId | ||
} | ||
|
||
const response = await kient._apiClient.fetch<APIResponse<ChatData>>('/chat', { | ||
method: 'POST', | ||
body: JSON.stringify(requestParams), | ||
}) | ||
|
||
const chat = new Chat(kient, response.data) | ||
return chat | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { Kient } from '../kient' | ||
import { Base } from './base' | ||
|
||
export interface ChatData { | ||
is_sent: boolean | ||
message_id: string | ||
} | ||
|
||
/** | ||
* Data structure of a chat message | ||
* | ||
* @group API Structures | ||
*/ | ||
export class Chat extends Base<ChatData> { | ||
/** | ||
* The id of the sent message | ||
*/ | ||
id: string | ||
|
||
/** | ||
* A boolean indicating if the message has been sent | ||
*/ | ||
isSent: boolean | ||
|
||
/** @internal */ | ||
constructor(kient: Kient, data: ChatData) { | ||
super(kient, data) | ||
|
||
this.id = data.message_id | ||
this.isSent = data.is_sent | ||
} | ||
} |