import axios from 'axios';
import ProfileSchema from '';
class SlackService {
private url: string = 'slack hooks services url';
constructor(private profileSchema: ProfileSchema) {}
private async send(payload: any) {
await axios.post(this.url, payload);
}
public async message() {
const payload = {
attachments: [{color: '#82D8EB'}]
}
}
public async error({ solanaTag, customerPublicKey, code, desc, ... }) {
const env = process.env.NODE_ENV === 'development' ? 'Dev' : 'Prod';
const ts = Date.now();
const fields = [ ... ];
if (network) fields.push({title: '', value: network.toUpperCase(), short: false});
if (token) fields.push({title: '', value: token.toUpperCase(), short: false});
fields.push({title: '', value: costomerPublicKey, short: false});
...
const payload = { text: `*[${env}] ${desc}*`, attachments: [{ ... }] };
await this.send(payload);
}
}
export default SlackService;
import ProfileSchema from './app/schema/profile';
import SlackService from './app/services/slack';
...
const slackService = new SlackService(profileSchema);
const apiService = new APIService(profileSchema, slackService); // 어디든 재사용 가능
...
class BroadcastService {
...
error(type: ErrorMessageType, code: string, desc?: string, data?: any) {
...
const message = { solanaTag: profile?.solanaTag, customerPublicKey: profile?.publicKey, code, desc, ...data};
this.slackService.error(message);
}
}
댓글