Send channel messages as AS bot if sender is unknown
This commit is contained in:
@@ -34,6 +34,7 @@ class MautrixTelegram {
|
|||||||
*/
|
*/
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
this.config = config
|
this.config = config
|
||||||
|
this.channelTelegramSender = new TelegramUser(this, -1)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MXID -> {@link MatrixUser} cache.
|
* MXID -> {@link MatrixUser} cache.
|
||||||
@@ -142,6 +143,9 @@ class MautrixTelegram {
|
|||||||
* @returns {Intent} The Matrix puppet intent for the given Telegram user.
|
* @returns {Intent} The Matrix puppet intent for the given Telegram user.
|
||||||
*/
|
*/
|
||||||
getIntentForTelegramUser(id) {
|
getIntentForTelegramUser(id) {
|
||||||
|
if (id === -1) {
|
||||||
|
return this.botIntent
|
||||||
|
}
|
||||||
return this.bridge.getIntentFromLocalpart(this.getUsernameForTelegramUser(id))
|
return this.bridge.getIntentFromLocalpart(this.getUsernameForTelegramUser(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,6 +286,9 @@ class MautrixTelegram {
|
|||||||
* @returns {TelegramUser} The TelegramUser object.
|
* @returns {TelegramUser} The TelegramUser object.
|
||||||
*/
|
*/
|
||||||
async getTelegramUser(id, { createIfNotFound = true } = {}) {
|
async getTelegramUser(id, { createIfNotFound = true } = {}) {
|
||||||
|
if (id === -1) {
|
||||||
|
return this.channelTelegramSender
|
||||||
|
}
|
||||||
// TODO remove this after bugs are fixed
|
// TODO remove this after bugs are fixed
|
||||||
if (isNaN(parseInt(id, 10))) {
|
if (isNaN(parseInt(id, 10))) {
|
||||||
const err = new Error("Fatal: non-int Telegram user ID")
|
const err = new Error("Fatal: non-int Telegram user ID")
|
||||||
|
|||||||
@@ -210,6 +210,7 @@ class Portal {
|
|||||||
console.error(err.stack)
|
console.error(err.stack)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const sender = await this.app.getTelegramUser(evt.from)
|
const sender = await this.app.getTelegramUser(evt.from)
|
||||||
await sender.intent.sendTyping(this.roomID, false)
|
await sender.intent.sendTyping(this.roomID, false)
|
||||||
|
|
||||||
|
|||||||
+13
-7
@@ -137,13 +137,19 @@ class TelegramPeer {
|
|||||||
channel: this.toInputObject(),
|
channel: this.toInputObject(),
|
||||||
})
|
})
|
||||||
info = info.chats[0]
|
info = info.chats[0]
|
||||||
const participants = await telegramPOV.client("channels.getParticipants", {
|
try {
|
||||||
channel: this.toInputObject(),
|
const participants = await telegramPOV.client("channels.getParticipants", {
|
||||||
filter: { _: "channelParticipantsRecent" },
|
channel: this.toInputObject(),
|
||||||
offset: 0,
|
filter: { _: "channelParticipantsRecent" },
|
||||||
limit: 1000,
|
offset: 0,
|
||||||
})
|
limit: 1000,
|
||||||
users = participants.users
|
})
|
||||||
|
users = participants.users
|
||||||
|
} catch (err) {
|
||||||
|
// Getting channel participants apparently requires admin.
|
||||||
|
// TODO figure out what to do about that ^
|
||||||
|
users = []
|
||||||
|
}
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unknown peer type ${this.type}`)
|
throw new Error(`Unknown peer type ${this.type}`)
|
||||||
|
|||||||
@@ -305,9 +305,11 @@ class TelegramPuppet {
|
|||||||
from = update.from_id
|
from = update.from_id
|
||||||
break
|
break
|
||||||
case "updateNewChannelMessage":
|
case "updateNewChannelMessage":
|
||||||
|
// TODO figure out how channel message signing works
|
||||||
|
from = -1
|
||||||
case "updateNewMessage":
|
case "updateNewMessage":
|
||||||
update = update.message // Message defined at message#90dddc11 in layer 71
|
update = update.message // Message defined at message#90dddc11 in layer 71
|
||||||
from = update.from_id
|
from = update.from_id || from
|
||||||
to = TelegramPeer.fromTelegramData(update.to_id, update.from_id, this.userID)
|
to = TelegramPeer.fromTelegramData(update.to_id, update.from_id, this.userID)
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -317,7 +319,6 @@ class TelegramPuppet {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(update)
|
|
||||||
portal = await this.app.getPortalByPeer(to)
|
portal = await this.app.getPortalByPeer(to)
|
||||||
|
|
||||||
if (update._ === "messageService") {
|
if (update._ === "messageService") {
|
||||||
|
|||||||
Reference in New Issue
Block a user