notifications
This commit is contained in:
parent
2602773980
commit
b21921242e
@ -110,8 +110,9 @@ export class RocketChatAdapter implements NotificationAdapter {
|
||||
|
||||
/**
|
||||
* Get user token for RocketChat API
|
||||
* Creates a token for the specified RocketChat user ID
|
||||
*/
|
||||
private async getUserToken(): Promise<{ authToken: string; userId: string } | null> {
|
||||
private async getUserToken(rocketChatUserId: string): Promise<{ authToken: string; userId: string } | null> {
|
||||
try {
|
||||
const adminHeaders = {
|
||||
'X-Auth-Token': process.env.ROCKET_CHAT_TOKEN!,
|
||||
@ -119,19 +120,37 @@ export class RocketChatAdapter implements NotificationAdapter {
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
|
||||
// Create token for the specific user
|
||||
const createTokenResponse = await fetch(`${this.baseUrl}/api/v1/users.createToken`, {
|
||||
method: 'POST',
|
||||
headers: adminHeaders
|
||||
headers: adminHeaders,
|
||||
body: JSON.stringify({
|
||||
userId: rocketChatUserId
|
||||
})
|
||||
});
|
||||
|
||||
if (!createTokenResponse.ok) {
|
||||
logger.error('[ROCKETCHAT_ADAPTER] Failed to create user token', {
|
||||
status: createTokenResponse.status,
|
||||
rocketChatUserId,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
const tokenData = await createTokenResponse.json();
|
||||
|
||||
if (!tokenData.success || !tokenData.data) {
|
||||
logger.error('[ROCKETCHAT_ADAPTER] Invalid token response', {
|
||||
response: tokenData,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
logger.debug('[ROCKETCHAT_ADAPTER] User token created', {
|
||||
rocketChatUserId,
|
||||
tokenUserId: tokenData.data.userId,
|
||||
});
|
||||
|
||||
return {
|
||||
authToken: tokenData.data.authToken,
|
||||
userId: tokenData.data.userId
|
||||
@ -139,6 +158,7 @@ export class RocketChatAdapter implements NotificationAdapter {
|
||||
} catch (error) {
|
||||
logger.error('[ROCKETCHAT_ADAPTER] Error getting user token', {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
rocketChatUserId,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
@ -165,7 +185,9 @@ export class RocketChatAdapter implements NotificationAdapter {
|
||||
|
||||
const rocketChatUserId = await this.getRocketChatUserId(email);
|
||||
if (!rocketChatUserId) {
|
||||
logger.debug('[ROCKETCHAT_ADAPTER] User not found in RocketChat');
|
||||
logger.debug('[ROCKETCHAT_ADAPTER] User not found in RocketChat', {
|
||||
emailHash: email ? Buffer.from(email.toLowerCase()).toString('base64').slice(0, 12) : null,
|
||||
});
|
||||
return {
|
||||
total: 0,
|
||||
unread: 0,
|
||||
@ -178,9 +200,16 @@ export class RocketChatAdapter implements NotificationAdapter {
|
||||
};
|
||||
}
|
||||
|
||||
const userToken = await this.getUserToken();
|
||||
logger.debug('[ROCKETCHAT_ADAPTER] Found RocketChat user', {
|
||||
rocketChatUserId,
|
||||
emailHash: Buffer.from(email.toLowerCase()).toString('base64').slice(0, 12),
|
||||
});
|
||||
|
||||
const userToken = await this.getUserToken(rocketChatUserId);
|
||||
if (!userToken) {
|
||||
logger.error('[ROCKETCHAT_ADAPTER] Could not get user token');
|
||||
logger.error('[ROCKETCHAT_ADAPTER] Could not get user token', {
|
||||
rocketChatUserId,
|
||||
});
|
||||
return {
|
||||
total: 0,
|
||||
unread: 0,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user