diff --git a/src/services/StreamLabs.js b/src/services/StreamLabs.js deleted file mode 100644 index 18e08f9..0000000 --- a/src/services/StreamLabs.js +++ /dev/null @@ -1,29 +0,0 @@ -const axios = require('axios').default; - -class StreamLabs { - constructor({ token }, logger) { - this.base = 'https://streamlabs.com/api/v1.0'; - this.token = token; - this.logger = logger; - } - - async alert({ message }) { - try { - await axios.post(`${this.base}/alerts`, { - access_token: this.token, - message, - type: 'follow', - }); - } catch (error) { - if (this.logger) { - this.logger.log(['error', 'streamlabs'], { data: error.response.data }); - } - - throw error; - } - } -} - -module.exports = { - StreamLabs, -}; diff --git a/src/services/StreamLabs.ts b/src/services/StreamLabs.ts new file mode 100644 index 0000000..9c916d9 --- /dev/null +++ b/src/services/StreamLabs.ts @@ -0,0 +1,41 @@ +import axios from 'axios'; + +interface StreamLabsConfig { + token: string; +} + +interface StreamLabsLogger { + log: (levels: string[], log: any) => void; +} + +interface StreamLabsAlert { + message: string; +} + +export class StreamLabs { + private base: string; + private token: string; + private logger: StreamLabsLogger; + + constructor({ token }: StreamLabsConfig, logger: StreamLabsLogger) { + this.base = 'https://streamlabs.com/api/v1.0'; + this.token = token; + this.logger = logger; + } + + async alert({ message }: StreamLabsAlert) { + try { + await axios.post(`${this.base}/alerts`, { + access_token: this.token, + message, + type: 'follow', + }); + } catch (error) { + if (this.logger) { + this.logger.log(['error', 'streamlabs'], { data: error.response.data }); + } + + throw error; + } + } +}