fix duplicate notifications on support chat request; fix transcript attachment filename
This commit is contained in:
29
src/bot.js
29
src/bot.js
@@ -64,9 +64,9 @@ class OcrccBot {
|
||||
}
|
||||
|
||||
async sendMessage(roomId, content) {
|
||||
logger.log("info", `SENDING MESSAGE: ${content.body}`)
|
||||
try {
|
||||
await this.client.sendMessage(roomId, content)
|
||||
logger.log("info", `SENT MESSAGE: ${content.body}`)
|
||||
} catch(err) {
|
||||
switch (err["name"]) {
|
||||
case "UnknownDeviceError":
|
||||
@@ -293,7 +293,7 @@ class OcrccBot {
|
||||
const file = fs.readFileSync(transcriptFile);
|
||||
const stats = fs.statSync(transcriptFile);
|
||||
|
||||
const url = await this.client.uploadContent(file, { rawResponse: false, type: 'text/plain' })
|
||||
const url = await this.client.uploadContent(file, { rawResponse: false, name: filename })
|
||||
logger.log('info', url)
|
||||
|
||||
const content = {
|
||||
@@ -304,7 +304,8 @@ class OcrccBot {
|
||||
mimetype: 'text/plain'
|
||||
},
|
||||
url: url.content_uri,
|
||||
showToUser: senderId
|
||||
showToUser: senderId,
|
||||
mimetype: 'text/plain'
|
||||
};
|
||||
|
||||
this.sendMessage(roomId, content);
|
||||
@@ -388,15 +389,19 @@ class OcrccBot {
|
||||
!this.joinedRooms.includes(member.roomId)
|
||||
) {
|
||||
try {
|
||||
const room = await this.client.joinRoom(member.roomId)
|
||||
logger.log("info", "AUTO JOINED ROOM => " + room.roomId)
|
||||
const currentDate = new Date()
|
||||
const chatDate = currentDate.toLocaleDateString()
|
||||
const chatTime = currentDate.toLocaleTimeString()
|
||||
const roomId = room.roomId.split(':')[0]
|
||||
const notification = `Incoming support chat at ${chatTime} (room ID: ${roomId})`
|
||||
this.sendTextMessage(this.config.FACILITATOR_ROOM_ID, notification);
|
||||
this.inviteFacilitators(room.roomId)
|
||||
const roomData = await this.client.getJoinedRooms()
|
||||
const joinedRooms = roomData["joined_rooms"]
|
||||
if (!joinedRooms.includes(member.roomId)) {
|
||||
const room = await this.client.joinRoom(member.roomId)
|
||||
logger.log("info", "AUTO JOINED ROOM => " + room.roomId)
|
||||
const currentDate = new Date()
|
||||
const chatDate = currentDate.toLocaleDateString()
|
||||
const chatTime = currentDate.toLocaleTimeString()
|
||||
const roomId = room.roomId.split(':')[0]
|
||||
const notification = `Incoming support chat at ${chatTime} (room ID: ${roomId})`
|
||||
this.sendTextMessage(this.config.FACILITATOR_ROOM_ID, notification);
|
||||
this.inviteFacilitators(room.roomId)
|
||||
}
|
||||
} catch(err) {
|
||||
logger.log("error", "ERROR JOINING ROOM => " + err)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ const {
|
||||
BOT_USERID,
|
||||
BOT_PASSWORD,
|
||||
BOT_DISPLAY_NAME,
|
||||
FACILITATOR_GROUP_ID,
|
||||
FACILITATOR_ROOM_ID,
|
||||
CHAT_OFFLINE_MESSAGE,
|
||||
CAPTURE_TRANSCRIPTS
|
||||
@@ -64,7 +63,6 @@ const botConfig = {
|
||||
BOT_USERID,
|
||||
BOT_PASSWORD,
|
||||
BOT_DISPLAY_NAME,
|
||||
FACILITATOR_GROUP_ID,
|
||||
FACILITATOR_ROOM_ID,
|
||||
CHAT_OFFLINE_MESSAGE,
|
||||
CAPTURE_TRANSCRIPTS
|
||||
|
||||
@@ -11,7 +11,6 @@ const {
|
||||
BOT_USERID,
|
||||
BOT_PASSWORD,
|
||||
BOT_DISPLAY_NAME,
|
||||
FACILITATOR_GROUP_ID,
|
||||
FACILITATOR_ROOM_ID,
|
||||
CAPTURE_TRANSCRIPTS,
|
||||
} = process.env;
|
||||
@@ -26,7 +25,6 @@ const botConfig = {
|
||||
BOT_USERID,
|
||||
BOT_PASSWORD,
|
||||
BOT_DISPLAY_NAME,
|
||||
FACILITATOR_GROUP_ID,
|
||||
FACILITATOR_ROOM_ID,
|
||||
CAPTURE_TRANSCRIPTS,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user