IHttp won't work in the app implement IPreMessageSentModify
lent85 opened this issue · comments
Ngô Thành Lê (Casper) commented
Develop a custom app with ability to call API and custom the message base on the response. But won't able to get the IHttp work in anyway.
Sample code:
public async executePreMessageSentModify(
message: IMessage, builder: IMessageBuilder, read: IRead, http: IHttp, persistence: IPersistence): Promise<IMessage> {
this.checkHttp(http, "executePreMessageSentModify");
}
private async checkHttp(http: IHttp, prefix: string): Promise<void> {
try {
const testResponse = await http.get('https://google.com', {
timeout: 3000,
strictSSL: false,
rejectUnauthorized: false
});
if (testResponse && testResponse.statusCode === 200) {
await this.getLogger().log('Precheck @ ' + prefix + ': HTTP object is okay to use');
} else {
await this.getLogger().log('Precheck @ ' + prefix + ': Got non-200 status code', testResponse ? testResponse.statusCode : 'No Response');
}
} catch (error) {
await this.getLogger().error('Precheck @ ' + prefix + ': HTTP object is not okay to use:', error.message);
}
}
this code always return the No Response
as testResponse is always undefined