```bash $ npm install --save notidog-client ```
npm install notidog-client``bash`
$ npm install --save notidog-client
`ts
import { NotiDog } from 'notidog-client';
// 채팅 도우미 서버 연결 처리
const client = NotiDog.create('{채팅 도우미 url}', '{채팅 도우미 인증 토큰}');
`
서비스별 사용자 정보 | user_id | service_id
---|---|---
부비라이브 | user_key의 문자형 | bubeelive
`ts`
const user: { user_id: string, service_id: string, } = client.user;
> 방송 참여자들의 채팅이나 후원 처리시 사용하는 이벤트
`tsON.OPENED
// 방송 이벤트 캐치
client
// 방송 시작됨
.on(EVENT.OPENED, () => {
console.log();ON.CLOSED
})
// 방송 종료됨
.on(EVENT.CLOSED, () => {
console.log();ON.CHAT - msg: ${data.msg}
})
// 방송자 채팅 처리 (공지, 타이머 등)
.on(EVENT.OWNER_CHAT, (data: OwnerChatEventData) => {
// data.msg: 방송자 채팅글
console.log();ON.CHAT - id: ${data.id} / name: ${data.name} / msg: ${data.msg}
})
// 모든 사용자 채팅 캐치
.on(EVENT.CHAT, (data: ChatEventData) => {
// data.id: 사용자 ID (부비라이브는 user_key)
// data.name: 사용자 이름
// data.msg: 사용자 채팅글
console.log();ON.COIN - id: ${data.id} / name: ${data.name} / count: ${data.count} / coin_name: ${data.coin_name}
})
// 사용자 후원 캐치
.on(EVENT.COIN, (data: CoinEventData) => {
// data.id: 사용자 ID (부비라이브는 user_key)
// data.name: 사용자 이름
// data.count: 사용자 후원 갯수
// data.coin_name: 후원 상품명 (부비라이브에서는 사용)
console.log();ON.USER_ENTERED - id: ${data.id} / name: ${data.name}
})
// 모든 사용자 입장 캐치
.on(EVENT.USER_ENTERED, (data: UserEnteredExitedData) => {
// data.id: 사용자 ID (부비라이브는 user_key)
// data.name: 사용자 이름
console.log();ON.USER_EXITED - id: ${data.id} / name: ${data.name}
})
// 모든 사용자 퇴장 캐치
.on(EVENT.USER_EXITED, (data: UserEnteredExitedData) => {
// data.id: 사용자 ID (부비라이브는 user_key)
// data.name: 사용자 이름
console.log();`
});
> 채팅 도우미의 설정 값 변경이나 파일 업로드 등의 동작에 대한 처리시 사용하는 이벤트
`tsON.CONFIG_UPDATED - resource
// 채팅 도우미 이벤트 캐치
client
// 설정값 변경시
.config.on(CONFIG_EVENT.CONFIG_UPDATED, (resource, config) => {
console.log(, resource, config, config);ON.CONFIG_DELETED - resource
})
// 설정값 삭제시
.config.on(CONFIG_EVENT.CONFIG_DELETED, (resource, config) => {
console.log(, resource, config, config);ON.ATTACHMENT_APPENDED - resource
})
// 파일 업로드시
.config.on(CONFIG_EVENT.ATTACHMENT_APPENDED, (resource, attachments: Array
console.log(, resource, attachments, attachments);`
});
> 변경시 CONFIG_EVENT.CONFIG_UPDATED 이벤트 호출 됩니다.
`tsconfig
// 채팅 도우미 사용자 설정
client.config.set(
'/msg',
{
message:{
data:{
title:'난 내가지킬께 필요읍따 ㅇㅇ',
msg:'[엉덩이팡팡팡]님의 방송이 시작되었습니다.',
extra:{
mode:'LIVE_START',
seq_key:673325,
site_key:'',
user_key:1012216,
pb_key:'',
diff_date:'',
gold:20000,
vod_key:673325,
title:'난 내가지킬께 필요읍따 ㅇㅇ'
}
},
android:{
priority:'high'
},
apns:{
payload:{
aps:{
alert:{
body:'[엉덩이팡팡팡]님의 방송이 시작되었습니다.'
},
badge:0,
sound:'default.wav',
'mutable-content':1
}
}
}
}
}
)
.then((config: any) => {
console.log(, config);`
});
`tsconfig
// 채팅 도우미 사용자 설정값 전체 확인
client.config.get('/')
.then((config: any) => {
console.log(, config);
});
// 채팅 도우미 사용자 설정값 확인
client.config.get('/msg/message/data/extra')
.then((config: any) => {
console.log(config, config);`
// {
// mode:'LIVE_START',
// seq_key:673325,
// site_key:'',
// user_key:1012216,
// pb_key:'',
// diff_date:'',
// gold:20000,
// vod_key:673325,
// title:'난 내가지킬께 필요읍따 ㅇㅇ'
// }
});
> 변경시 CONFIG_EVENT.CONFIG_DELETED 이벤트 호출 됩니다.
`tssuccess?
// 채팅 도우미 사용자 설정값 삭제
client.config.delete('/msg/message/data/extra')
.then((result: boolean) => {
console.log(, result);`
});
> 변경시 CONFIG_EVENT.ATTACHMENT_APPENDED 이벤트 호출 됩니다.
#### HTMLFormElement 또는 Array
`html HTML 코드``tsfile
// 채팅 도우미 파일 업로드 - HTMLFormElement
client.config.upload('/signature', document.querySelector('form'))
.then((files: Array
files?.forEach((file: AttachmentResultData) => {
console.log(, file);`
// {
// original_name: '202508.png',
// url: 'https://notidog-static.codewiz.kr/bubeelive/991/signature/1759279530686-583066384.png',
// size: 43690
// }
});
});`
#### HTMLInputElement 또는 Arrayhtml HTML 코드``tsfile
// 채팅 도우미 파일 업로드 - HTMLInputElement
client.config.upload('/signature', document.querySelector('#upload1'))
.then((files: Array
files?.forEach((file: AttachmentResultData) => {
console.log(, file);`
// {
// original_name: '202508.png',
// url: 'https://notidog-static.codewiz.kr/bubeelive/991/signature/1759279530686-583066384.png',
// size: 43690
// }
});
});`
#### FileList 또는 Arrayhtml HTML 코드``tsfile
// 채팅 도우미 파일 업로드 - HTMLInputElement
client.config.upload('/signature', document.querySelector('#upload1').files)
.then((files: Array
files?.forEach((file: AttachmentResultData) => {
console.log(, file);`
// {
// original_name: '202508.png',
// url: 'https://notidog-static.codewiz.kr/bubeelive/991/signature/1759279530686-583066384.png',
// size: 43690
// }
});
});`
#### File 또는 Arrayhtml HTML 코드``tsfile
// 채팅 도우미 파일 업로드 - HTMLInputElement
client.config.upload('/signature', document.querySelector('#upload1').files.item(0))
.then((files: Array
files?.forEach((file: AttachmentResultData) => {
console.log(, file);`
// {
// original_name: '202508.png',
// url: 'https://notidog-static.codewiz.kr/bubeelive/991/signature/1759279530686-583066384.png',
// size: 43690
// }
});
});
`tsfile
// 채팅 도우미 파일 목록
client.config.files('/signature')
.then((files: Array
files?.forEach((file: AttachmentData) => {
console.log(, file);
// {
// url: 'https://notidog-static.codewiz.kr/bubeelive/991/signature/1759279530686-583066384.png',
// file_name: '1759279530686-583066384.png',
// size: 43690
// }
// or
// {
// url: 'https://notidog-static.codewiz.kr/bubeelive/991/signature/1759279530686-583066384-original.png',
// file_name: '1759279530686-583066384-original.png',
// original_name: 'original.png',
// created_at: 1759279530686,
// size: 43690
// }
});
});
// 서비스별 기본 이미지 파일 목록
client.config.defaultImages()
.then((files: Array
files?.forEach((file: AttachmentData) => {
console.log(file, file);
// {
// url: 'https://notidog-static.codewiz.kr/bubeelive/991/signature/1759279530686-583066384.png',
// file_name: '1759279530686-583066384.png',
// size: 43690
// }
});
});
// 서비스별 기본 사운드 파일 목록
client.config.defaultSounds()
.then((files: Array
files?.forEach((file: AttachmentData) => {
console.log(file, file);`
// {
// url: 'https://notidog-static.codewiz.kr/bubeelive/991/signature/1759279530686-583066384.mp3',
// file_name: '1759279530686-583066384.mp3',
// size: 43690
// }
});
});
`tsurl
// TTS 파일 생성, 한글 + 여성
client.tts('아무개님 안녕하세요')
.then((url: string|null) => {
console.log(, url);
});
// TTS 파일 생성, 언어 및 성별 설정
client.tts('아무개님 안녕하세요', 'ko-KR', 'female')
.then((url: string|null) => {
console.log(url, url);`
});
`ts
// 방송자 채팅 테스트용
client.fireTest(
event: EVENT.OWNER_CHAT,
{
msg: '방송자 채팅 테스트'
}: OwnerChatEventData
);
// 참여자 채팅 테스트용
client.fireTest(
event: EVENT.CHAT,
{
id: '1',
name: '김삿갓',
msg: '김삿갓 채팅 테스트'
}: ChatEventData
);
// 참여자 후원 테스트용
client.fireTest(
event: EVENT.COIN,
{
id: '1',
name: '김삿갓',
count: 1000,
coin_name: '1000꿀'
}: CoinEventData
);
// 참여자 입장 테스트용
client.fireTest(
event: EVENT.USER_ENTERED,
{
id: '1',
name: '김삿갓',
}: UserEnteredExitedData
);
// 참여자 퇴장 테스트용
client.fireTest(
event: EVENT.USER_EXITED,
{
id: '1',
name: '김삿갓',
}: UserEnteredExitedData
);
``