mautrix / twitter Goto Github PK
View Code? Open in Web Editor NEWA Matrix-Twitter DM puppeting bridge
License: GNU Affero General Public License v3.0
A Matrix-Twitter DM puppeting bridge
License: GNU Affero General Public License v3.0
If a user mentions a Twitter user on Matrix, it appears on the Twitter end in plain text as the Matrix user's display name.
Is this a fundamental limitation of the bridge? If not, I would be interested in contributing a fix.
As the title says, it clutters my matrix client, is there a way to disable requests from being bridged ? especially those "Note: Twitter has marked this as a "low quality" message." ?
ones
Right now "Low quality" DM's are bridge to matrix as normal private chats and only a warning similar to
"This is a message request. Replying here will accept the request. Note: Twitter has marked this as a "low quality" message." is shown in the initial private chat header.
Add an option in the bridge registration config file that to instead disable receiving DM's (and creating portals for those DM's) that are marked as low quality by Twitter.
Turns out there's no difference at all except in some old DBMSes like MySQL
It looks like Twitter DM's will finally support replying to messages soon; would be great for this bridge to also support this when using Twitter DM's:
https://twitter.com/elonmusk/status/1656084243905384449
(Also submitted to Beeper support as DES-11053)
Synapse: 1.44
Mautrix/twitter: mautrix-twitter 0.1.2+dev.6bd5fb12
After adding appservice into homeserver.yaml every run give:
[2021-10-20 14:33:46,718] [[email protected]] Initializing mautrix-twitter 0.1.2+dev.6bd5fb12
[2021-10-20 14:33:46,724] [[email protected]] Initialization complete in 0.3 seconds
[2021-10-20 14:33:46,725] [[email protected]] Running startup actions...
[2021-10-20 14:33:46,725] [[email protected]] Connecting to postgres://<redacted>
[2021-10-20 14:33:47,395] [[email protected]] Database at v3, not upgrading
[2021-10-20 14:33:47,399] [[email protected]] Starting appservice...
[2021-10-20 14:33:47,400] [[email protected]] Starting appservice web server on 0.0.0.0:29327
[2021-10-20 14:33:47,401] [[email protected]] Ensuring connectivity to homeserver
[2021-10-20 14:33:47,422] [[email protected]] Logging in with bridge bot user
[2021-10-20 14:33:47,428] [[email protected]] Found device ID in database: <redacted>
[2021-10-20 14:33:47,443] [[email protected]] End-to-bridge encryption support is enabled
[2021-10-20 14:33:47,446] [[email protected]] Initializing appservice bot
[2021-10-20 14:33:47,449] [[email protected]] Unexpected error in main event loop
Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/mautrix/util/program.py", line 190, in _run
self.loop.run_until_complete(self.start())
File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/usr/lib/python3.9/site-packages/mautrix_twitter/__main__.py", line 76, in start
await super().start()
File "/usr/lib/python3.9/site-packages/mautrix/bridge/bridge.py", line 169, in start
await super().start()
File "/usr/lib/python3.9/site-packages/mautrix/util/program.py", line 213, in start
await asyncio.gather(*(self.startup_actions or []))
File "/usr/lib/python3.9/site-packages/mautrix/util/program.py", line 246, in _unpack_async_iterator
async for task in iterable:
File "/usr/lib/python3.9/site-packages/mautrix_twitter/user.py", line 91, in <genexpr>
return (user.try_connect() async for user in cls.all_logged_in())
File "/usr/lib/python3.9/site-packages/mautrix_twitter/user.py", line 415, in all_logged_in
users = await super().all_logged_in()
File "/usr/lib/python3.9/site-packages/mautrix_twitter/db/user.py", line 71, in all_logged_in
rows = await cls.db.fetch(q)
File "/usr/lib/python3.9/site-packages/mautrix/util/async_db/database.py", line 90, in fetch
return await conn.fetch(query, *args, timeout=timeout)
File "/usr/lib/python3.9/site-packages/asyncpg/connection.py", line 601, in fetch
return await self._execute(
File "/usr/lib/python3.9/site-packages/asyncpg/connection.py", line 1639, in _execute
result, _ = await self.__execute(
File "/usr/lib/python3.9/site-packages/asyncpg/connection.py", line 1664, in __execute
return await self._do_execute(
File "/usr/lib/python3.9/site-packages/asyncpg/connection.py", line 1691, in _do_execute
stmt = await self._get_statement(
File "/usr/lib/python3.9/site-packages/asyncpg/connection.py", line 393, in _get_statement
statement = await self._protocol.prepare(
File "asyncpg/protocol/protocol.pyx", line 168, in prepare
asyncpg.exceptions.UndefinedColumnError: column "twid" does not exist
HINT: Perhaps you meant to reference the column "user.mxid" or the column "user.fbid".
Expected result:
no error during reading database: no missing columns
@tulir Do You have idea how to fix it?
Regards
I noticed that my twitter bridge was not picking up new messages, so I tried to issue a 'sync' which gets me the following response:
Unhandled error while handling command:
Traceback (most recent call last): File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/appservice/api/intent.py", line 321, in ensure_joined await self.join_room(room_id, max_retries=0) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/appservice/api/intent.py", line 80, in wrapper return await __method(*args, **kwargs) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/client/api/rooms.py", line 253, in join_room content=content, query_params=query_params) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/api.py", line 233, in request return await self._send(method, full_url, content, query_params, headers or {}) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/api.py", line 160, in _send errcode=errcode, message=message) mautrix.errors.request.MForbidden: You are not invited to this room. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/appservice/api/intent.py", line 321, in ensure_joined await self.join_room(room_id, max_retries=0) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/appservice/api/intent.py", line 80, in wrapper return await __method(*args, **kwargs) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/client/api/rooms.py", line 253, in join_room content=content, query_params=query_params) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/api.py", line 233, in request return await self._send(method, full_url, content, query_params, headers or {}) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/api.py", line 160, in _send errcode=errcode, message=message) mautrix.errors.request.MForbidden: You are not invited to this room. The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/bridge/commands/handler.py", line 405, in handle await self._run_handler(handler, evt) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/bridge/commands/handler.py", line 290, in __call__ return await self._handler(evt) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix_twitter/commands/conn.py", line 45, in sync await evt.sender.sync() File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix_twitter/user.py", line 241, in sync await self.handle_conversation_update(conversation, create_portal=i < limit) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix_twitter/user.py", line 288, in handle_conversation_update await portal.update_info(evt) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix_twitter/portal.py", line 388, in update_info await self._update_participants(conv.participants) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix_twitter/portal.py", line 423, in _update_participants await puppet.intent_for(self).ensure_joined(self.mxid) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/appservice/api/intent.py", line 327, in ensure_joined await self.bot.invite_user(room_id, self.mxid) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/appservice/api/intent.py", line 91, in wrapper await __self.ensure_joined(room_id) File "/opt/venvs/mautrix-twitter/lib/python3.7/site-packages/mautrix/appservice/api/intent.py", line 325, in ensure_joined raise IntentError(f"Failed to join room {room_id} as {self.mxid}") from e mautrix.errors.base.IntentError: Failed to join room !xxxxxxxxxx:toke.dk as @twitterbot:toke.dk
I tried upgrading the bridge to the latest git version, which didn't help either. I did get new messages to appear after restarting the bridge, but I still get that error when issuing a 'sync' command in the control channel.
hi,After inputting ct value, login prompt error:
Failed to log in: 38: countryCode parameter is missing.
Help. Thx
I get this Error :( on Python 3.8-3.9 with Postgres
matrix-appservice-twitter) matrix@webapps:/home/opt/matrix/bridges/matrix-appservice-twitter$ /home/opt/matrix/bridges/matrix-appservice-twitter/bin/python -m mautrix_twitter
[2020-11-18 04:05:54,757] [[email protected]] Initializing mautrix-twitter 0.1.1+dev.unknown
[2020-11-18 04:05:54,762] [[email protected]] Initialization complete in 0.24 seconds
[2020-11-18 04:05:54,849] [[email protected]] Ensuring connectivity to homeserver
[2020-11-18 04:05:55,499] [[email protected]] Startup actions complete in 0.74 seconds, now running forever
[2020-11-18 04:05:55,655] [[email protected].@dom1nic:matrix.3dns.eu] Exception while syncing conversations
Traceback (most recent call last):
File "/home/opt/matrix/bridges/matrix-appservice-twitter/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 117, in _dict_to_attrs
obj = attrs_type(**new_items)
TypeError: __init__() missing 3 required positional arguments: 'entries', 'users', and 'conversations'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/opt/matrix/bridges/matrix-appservice-twitter/lib/python3.8/site-packages/mautrix_twitter/user.py", line 216, in _try_initial_sync
await self.sync()
File "/home/opt/matrix/bridges/matrix-appservice-twitter/lib/python3.8/site-packages/mautrix_twitter/user.py", line 230, in sync
resp = await self.client.inbox_initial_state(set_poll_cursor=False)
File "/home/opt/matrix/bridges/matrix-appservice-twitter/lib/python3.8/site-packages/mautwitdm/poller.py", line 109, in inbox_initial_state
response = InitialStateResponse.deserialize(data["inbox_initial_state"])
File "/home/opt/matrix/bridges/matrix-appservice-twitter/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 282, in deserialize
return _dict_to_attrs(cls, data)
File "/home/opt/matrix/bridges/matrix-appservice-twitter/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 122, in _dict_to_attrs
raise SerializerError(
mautrix.types.util.serializable.SerializerError: Missing value for required key entries in InitialStateResponse
[2020-11-18 04:05:56,529] [[email protected].@dom1nic:matrix.3dns.eu] Fatal error while polling
Traceback (most recent call last):
File "/home/opt/matrix/bridges/matrix-appservice-twitter/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 117, in _dict_to_attrs
obj = attrs_type(**new_items)
TypeError: __init__() missing 3 required positional arguments: 'entries', 'users', and 'conversations'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/opt/matrix/bridges/matrix-appservice-twitter/lib/python3.8/site-packages/mautwitdm/poller.py", line 138, in poll_forever
await self._poll_forever()
File "/home/opt/matrix/bridges/matrix-appservice-twitter/lib/python3.8/site-packages/mautwitdm/poller.py", line 163, in _poll_forever
resp = await self.inbox_initial_state()
File "/home/opt/matrix/bridges/matrix-appservice-twitter/lib/python3.8/site-packages/mautwitdm/poller.py", line 109, in inbox_initial_state
response = InitialStateResponse.deserialize(data["inbox_initial_state"])
File "/home/opt/matrix/bridges/matrix-appservice-twitter/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 282, in deserialize
return _dict_to_attrs(cls, data)
File "/home/opt/matrix/bridges/matrix-appservice-twitter/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 122, in _dict_to_attrs
raise SerializerError(
mautrix.types.util.serializable.SerializerError: Missing value for required key entries in InitialStateResponse
[2020-11-18 04:05:56,653] [[email protected]] 127.0.0.1 [18/Nov/2020:03:05:56 +0000] "PUT /transactions/34?access_token=iscjdiaihxlo3h3bemcjibzxfoul87ptyvdc16v9wqnmuengm9w42it6bj2tiui8 HTTP/1.1" 200 158 "-" "Synapse/1.22.1"
I have two Twitter accounts and I want to manage their messages together.
However, mautrix-twitter’s Twitter Bridge Bot can only login one account ones. So I started thinking whether I could start 2 mautrix-twitter bridges to catch all messages.
I think I’m 90% done: I could login using the second twitter bot, however, I could not receive messages because there’re still some conflicts.
Here is how I deploy the second bridge:
docker exec postgres createdb -U synapse_user -O synapse_user matrix_twitter_s1
mkdir mautrix-twitter-s1
docker run --rm -v `pwd`/mautrix-twitter-s1:/data:z dock.mau.dev/mautrix/twitter:latest
In mautrix-twitter-s1/config.yaml
(only listing changes)
homeserver:
address: http://synapse:8008
domain: example.com
appservice:
address: http://mautrix-twitter-s1:29328
port: 29328
database: postgres://synapse_user:hello@postgres/matrix_twitter_s1?sslmode=disable
id: twitter-s1
bot_username: twitterbot-s1
bot_displayname: Twitter bridge bot s1
bridge:
username_template: twitter_s1_{userid}
displayname_template: "{displayname} (Twitter)"
double_puppet_server_map:
matrix.server: https://example.com
login_shared_secret_map:
example.com: <redacted>
command_prefix: "!tw1"
permissions:
example.com: user
"@admin:example.com": admin
After editing the config, I run
docker run --rm -v `pwd`/mautrix-twitter-s1:/data:z dock.mau.dev/mautrix/twitter:latest
again to get registration.yaml
:
id: twitter-s1
as_token: <redacted>
hs_token: <redacted>
namespaces:
users:
- exclusive: true
regex: '@twitter_s1_.*:example\.com'
- exclusive: true
regex: '@twitterbot\-s1:example\.com'
aliases: []
url: http://mautrix-twitter-s1:29328
sender_localpart: <redacted>
rate_limited: false
de.sorunome.msc2409.push_ephemeral: true
push_ephemeral: true
Then I register the bridge to synapse:
cp mautrix-twitter-s1/registration.yaml synapse/tw-s1-registration.yaml
sudo chown 991:991 synapse/tw-s1-registration.yaml
And in synapse/homeserver.yaml
:
app_service_config_files:
- /data/tw-s1-registration.yaml
Then I edit the docker-compose.yml, adding lines below. I have already set another bridge by then, so here I show thier config together.
mautrix-twitter:
hostname: mautrix-twitter
container_name: mautrix-twitter
image: dock.mau.dev/mautrix/twitter:latest
restart: unless-stopped
depends_on:
synapse:
condition: service_healthy
volumes:
- ./mautrix-twitter:/data
networks:
- matrix-net
mautrix-twitter-s1:
hostname: mautrix-twitter-s1
container_name: mautrix-twitter-s1
image: dock.mau.dev/mautrix/twitter:latest
restart: unless-stopped
depends_on:
synapse:
condition: service_healthy
volumes:
- ./mautrix-twitter-s1:/data
networks:
- matrix-net
Then I use docker-compose up -d
to start my service, start a chat with @twitterbot-s1:example.com
.
...but when the brige try to sync msgs, it encounter such problems:
[2022-12-26 04:02:50,819] [[email protected].@arcsionlin:example.com] Failed to update own puppet info
Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/mautrix_twitter/user.py", line 326, in _try_sync_puppet
await puppet.update_info(user_info)
File "/usr/lib/python3.10/site-packages/mautrix_twitter/puppet.py", line 114, in update_info
update = await self._update_name(info) or update
File "/usr/lib/python3.10/site-packages/mautrix_twitter/puppet.py", line 132, in _update_name
await self.default_mxid_intent.set_displayname(self.name)
File "/usr/lib/python3.10/site-packages/mautrix/appservice/api/intent.py", line 126, in wrapper
await __self.ensure_registered()
File "/usr/lib/python3.10/site-packages/mautrix/appservice/api/intent.py", line 625, in ensure_registered
await self._register()
File "/usr/lib/python3.10/site-packages/mautrix/api.py", line 401, in request
resp_data, resp = await self._send(
File "/usr/lib/python3.10/site-packages/mautrix/api.py", line 256, in _send
raise make_request_error(
mautrix.errors.request.MExclusive: This user ID is reserved by an application service.
I tried to change displayname_template from "{displayname} (Twitter)"
to "{displayname} (Twitter-s1)"
in order to solve possible conflicts, but problem remains.
Could anyone give me some ideas on how should I solve this? Or, should I attach the configration of my first twitter brige (which works fine)?
The above error has been sent every 15 minutes for the last twelve hours or so.
Not sure if its my issue or not....
Exception while syncing conversations
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 112, in _dict_to_attrs
obj = attrs_type(**new_items)
TypeError: __init__() missing 1 required positional argument: 'indices'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/mautrix_twitter/user.py", line 136, in _try_initial_sync
await self.sync()
File "/usr/lib/python3.8/site-packages/mautrix_twitter/user.py", line 143, in sync
resp = await self.client.inbox_initial_state(set_poll_cursor=False)
File "/usr/lib/python3.8/site-packages/mautwitdm/poller.py", line 87, in inbox_initial_state
response = InitialStateResponse.deserialize(data["inbox_initial_state"])
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 268, in deserialize
return _dict_to_attrs(cls, data)
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 107, in _dict_to_attrs
new_items[name] = _try_deserialize(field.type, value, field.default,
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 128, in _try_deserialize
return _deserialize(cls, value, default)
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 179, in _deserialize
return [_deserialize(item_cls, item) for item in value]
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 179, in <listcomp>
return [_deserialize(item_cls, item) for item in value]
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 165, in _deserialize
return _dict_to_attrs(cls, value, default, default_if_empty=True)
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 107, in _dict_to_attrs
new_items[name] = _try_deserialize(field.type, value, field.default,
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 128, in _try_deserialize
return _deserialize(cls, value, default)
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 170, in _deserialize
return _deserialize(cls.__args__[0], value, default)
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 165, in _deserialize
return _dict_to_attrs(cls, value, default, default_if_empty=True)
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 107, in _dict_to_attrs
new_items[name] = _try_deserialize(field.type, value, field.default,
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 128, in _try_deserialize
return _deserialize(cls, value, default)
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 165, in _deserialize
return _dict_to_attrs(cls, value, default, default_if_empty=True)
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 107, in _dict_to_attrs
new_items[name] = _try_deserialize(field.type, value, field.default,
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 128, in _try_deserialize
return _deserialize(cls, value, default)
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 170, in _deserialize
return _deserialize(cls.__args__[0], value, default)
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 165, in _deserialize
return _dict_to_attrs(cls, value, default, default_if_empty=True)
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 107, in _dict_to_attrs
new_items[name] = _try_deserialize(field.type, value, field.default,
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 128, in _try_deserialize
return _deserialize(cls, value, default)
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 170, in _deserialize
return _deserialize(cls.__args__[0], value, default)
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 165, in _deserialize
return _dict_to_attrs(cls, value, default, default_if_empty=True)
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 117, in _dict_to_attrs
raise SerializerError(
mautrix.types.util.serializable.SerializerError: Missing value for required key indices in MessageAttachmentTweet
Exception while syncing conversations
Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/mautrix/types/util/serializable_attrs.py", line 112, in _dict_to_attrs
obj = attrs_type(**new_items)
TypeError: __init__() missing 1 required positional argument: 'indices'
It sounds like DM with a signle person a created with a name with that pattern:
{self:displayName} {recipient:displayName} (Twitter)
Current configuration is the original one: {displayName} (Twitter)
.
May it be possible to filter displayName
of my own name?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.