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
|
* 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 {
|
try {
|
||||||
const adminHeaders = {
|
const adminHeaders = {
|
||||||
'X-Auth-Token': process.env.ROCKET_CHAT_TOKEN!,
|
'X-Auth-Token': process.env.ROCKET_CHAT_TOKEN!,
|
||||||
@ -119,19 +120,37 @@ export class RocketChatAdapter implements NotificationAdapter {
|
|||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Create token for the specific user
|
||||||
const createTokenResponse = await fetch(`${this.baseUrl}/api/v1/users.createToken`, {
|
const createTokenResponse = await fetch(`${this.baseUrl}/api/v1/users.createToken`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: adminHeaders
|
headers: adminHeaders,
|
||||||
|
body: JSON.stringify({
|
||||||
|
userId: rocketChatUserId
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!createTokenResponse.ok) {
|
if (!createTokenResponse.ok) {
|
||||||
logger.error('[ROCKETCHAT_ADAPTER] Failed to create user token', {
|
logger.error('[ROCKETCHAT_ADAPTER] Failed to create user token', {
|
||||||
status: createTokenResponse.status,
|
status: createTokenResponse.status,
|
||||||
|
rocketChatUserId,
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tokenData = await createTokenResponse.json();
|
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 {
|
return {
|
||||||
authToken: tokenData.data.authToken,
|
authToken: tokenData.data.authToken,
|
||||||
userId: tokenData.data.userId
|
userId: tokenData.data.userId
|
||||||
@ -139,6 +158,7 @@ export class RocketChatAdapter implements NotificationAdapter {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('[ROCKETCHAT_ADAPTER] Error getting user token', {
|
logger.error('[ROCKETCHAT_ADAPTER] Error getting user token', {
|
||||||
error: error instanceof Error ? error.message : String(error),
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
rocketChatUserId,
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -165,7 +185,9 @@ export class RocketChatAdapter implements NotificationAdapter {
|
|||||||
|
|
||||||
const rocketChatUserId = await this.getRocketChatUserId(email);
|
const rocketChatUserId = await this.getRocketChatUserId(email);
|
||||||
if (!rocketChatUserId) {
|
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 {
|
return {
|
||||||
total: 0,
|
total: 0,
|
||||||
unread: 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) {
|
if (!userToken) {
|
||||||
logger.error('[ROCKETCHAT_ADAPTER] Could not get user token');
|
logger.error('[ROCKETCHAT_ADAPTER] Could not get user token', {
|
||||||
|
rocketChatUserId,
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
total: 0,
|
total: 0,
|
||||||
unread: 0,
|
unread: 0,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user