Rocket.Chat.Apps-engine icon indicating copy to clipboard operation
Rocket.Chat.Apps-engine copied to clipboard

IHttp won't work in the app implement IPreMessageSentModify

Open lent85 opened this issue 2 years ago • 0 comments

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

lent85 avatar Sep 13 '23 13:09 lent85