Code Monkey home page Code Monkey logo

matrix-appservice-tg's Introduction

THIS PROJECT IS ON HOLD

This project is not actively developed, maintained or supported at the moment. It is not recommended for production use.

For a working Telegram bridge, please check out https://github.com/tulir/mautrix-telegram

ARCHIVED README

Installation

$ git clone ...
$ cd matrix-appservice-tg
$ npm install

Setup

  1. Create a new Matrix room to act as the administration control room. Note its internal room ID.

  2. Create a telegram-config.yaml file for global configuration. There is a sample one to begin with in config/telegram-config-sample.yaml you may wish to copy and edit as appropriate. This needs the following keys:

    matrix_homeserver: "http URL pointing at the homeserver"
    
    matrix_user_domain: "domain part of the homeserver's name. Used for
                         ghost username generation"
    
    username_template: "template for virtual users, e.g. telegram_${USER}"
    
    matrix_admin_room: "the ID of the room created in step 2"
    
    auth_key_password: "a random string used to obfuscate authentication keys
                        stored in the user database"
  3. Pick/decide on a spare local TCP port number to run the application service on. This needs to be visible to the homeserver - take care to configure firewalls correctly if that is on another machine to the bridge. The port number will be noted as $PORT in the remaining instructions.

  4. Generate the appservice registration file (if the application service runs on the same server you can use localhost as $URL):

    $ node index.js --generate-registration -f telegram-registration.yaml  -u $URL:$PORT
  5. Start the actual application service. You can use forever

    $ forever start index.js --config telegram-config.yaml --port $PORT

    or node

    $ node index.js --config telegram-config.yaml --port $PORT
  6. Copy the newly-generated telegram-registration.yaml file to the homeserver. Add the registration file to your homeserver config (default homeserver.yaml):

    app_service_config_files:
       - ...
       - "/path/to/telegram-registration.yaml"

    Don't forget - it has to be a YAML list of strings, not just a single string.

    Restart your homeserver to have it reread the config file and establish a connection to the bridge.

  7. Invite the newly-created @telegrambot:DOMAIN user into the admin control room created at step 1.

The bridge should now be running.

matrix-appservice-tg's People

Contributors

ara4n avatar jaywink avatar leonerd avatar valodim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

matrix-appservice-tg's Issues

License

Please add a license file.

What to do next after configure and start Matrix Telegram bridge service?

I have succesfully configure and run Matrix Telegram bridge from your git, and see in output:

Matrix-side listening on port 8093

I have create a room, invite @telegrambot:myhomeserverdomain.com user to it and I see no output. What to do next? How to debug and use it?

Where can I see the list of available commands?
I try popular commands, but it answer me:
Unrecognised command: !help
Unrecognised command: !create
Unrecognised command: !list

Error: Expected the 'username_template' to contain the string ${ID}

node index.js --config ./config/telegram-config.yaml --port 8001
Loading config file /home/sya/telematrix/matrix-appservice-tg/config/telegram-config.yaml
Matrix-side listening on port 8001
/home/sya/telematrix/matrix-appservice-tg/node_modules/olm/olm.js:19
"undefined"!==typeof module&&(module.exports=a);process.on("uncaughtException",function(a){if(!(a instanceof T))throw a;});a.inspect=function(){return"[Emscripten Module object]"}}else if(ma)a.print||(a.print=print),"undefined"!=typeof printErr&&(a.printErr=printErr),a.read="undefined"!=typeof read?read:function(){throw"no read() available (jsc?)";},a.readBinary=function(a){if("function"===typeof readbuffer)return new Uint8Array(readbuffer(a));a=read(a,"binary");z("object"===typeof a);return a},"undefined"!=
                                                                                                                ^

Error: Expected the 'username_template' to contain the string ${ID}
    at new Main (/home/sya/telematrix/matrix-appservice-tg/lib/Main.js:62:15)
    at Object.run (/home/sya/telematrix/matrix-appservice-tg/index.js:22:10)
    at Cli._startWithConfig (/home/sya/telematrix/matrix-appservice-tg/node_modules/matrix-appservice-bridge/lib/components/cli.js:180:15)
    at Cli.run (/home/sya/telematrix/matrix-appservice-tg/node_modules/matrix-appservice-bridge/lib/components/cli.js:139:10)
    at Object.<anonymous> (/home/sya/telematrix/matrix-appservice-tg/index.js:24:4)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:427:7)
    at startup (bootstrap_node.js:151:9)
    at bootstrap_node.js:542:3

Node version v7.10.0
npm version v4.2.0

npm treats package.json as invalid by default

npm was complaining that package.json is invalid

npm ERR! Failed to parse json
npm ERR! Unexpected token } in JSON at position 554 while parsing near '...nse": "Apache-2.0",
npm ERR! }
npm ERR! '
npm ERR! File: /tmp/matrix-appservice-tg/package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR! 
npm ERR! Tell the package author to fix their package.json file. JSON.parse

It's easily fixed by removing a trailing comma from the "license" line

Mapping Telegram concepts to Matrix concepts

I just started thinking about improving this bridge and getting it up to speed with the IRC bridges.

Before I start writing code, I wanted to be certain the concepts were well mapped between the two worlds, so that we do not end up being stuck by a lack of consistency. So first, I believe this bridge should remain a pupetting bridge, and given the current state of Telegram APIs, there is no way we get a full two-way bridges without a bot on the Telegram side.

Inventory

Here are the concepts that I think are interested to map from Telegram:

  • registration and authentication (I don't see why we should not be able to create a Telegram account from Matrix!)
  • users, of course, which can be identified by username or after sharing one's contact list, have a profile and avatar;
  • direct chats with users;
  • group chats, with multiple users, including description and group picture;
  • channels;
  • message edition and deletion;
  • attached files.

On the other end, the following concepts should not be mapped:

  • history, I don't see how we can map history and scrollback properly;
  • end to end encrypted chats, at least for now, the bridge breaking the encryption anyway;
  • voice/video call, there is no way we can map that in the near future.

I am hesitating for the following concepts, still thinking maybe about planning to include them but not short-term:

  • geochat (I even have no idea what they are);
  • self-destructing messages (doable, but not that easy to implement).

Registration and authentication

I think the overall process should be self services. It could be made available through a bot, or through a widget, or a combination of the two. I still have to dig into the features widgets provide to see what can be implemented through a widget exactly.

Multi-step authentication should be mapped to a multistep questoin/response on Matrix.

Users

Telegram has a distinction between multiple types of users:

  • the current user;
  • a user from the contact list;
  • a user not from the contact list, from which a phone number is known;
  • a user not from the contact list.

Users can be discovered by username, or by other means (uploaded contact list), in which case they are identified by an integer. Unfortunately, usernames, despite being unique, can vary (a user can switch username). Also, the user integer identifier is unique across all types of users.

Therefore, a suggestion would be to use @prefix_<id> for every user, and have a separate mechanism to discover users by username (bot command, or anything else).

I guess we could implement something for discovering new users based on their phone number, but I do not believe that should be mapped to mxids or room aliases.

Direct chats and group chats

There are two dinstinct kinds of chat on Telegram, that one cannot mix (impossible to invite additional members to a direct chat). Also, both direct chats and group chats are identified by an integer id, only unique in its scope (either the user id, or the room id). Additionally, a direct chat can only be opened once with each user.

There is no strong obligation on using aliases to map these rooms: the appservice should automatically invite the Matrix user to rooms that he is not part of. Leaving a room should leave the actual Telegram room.

Also, to match the distinction between direct chat and group chats, two conditions should be applied:

  • one should not be allowed to invite people to a room mapped with a direct chat (this can be accomplished with room permissions I believe)
  • one should not be allowed to have two different rooms open for direct chat with the same user.

Channels

Channels are simple group chats with access restrictions. They are identified by name, so one should be able to find them at #prefix_#<name>.

Message edition and deletion

Editing a message on Telegram is only allowed for the latest messages. It could be reflected on Matrix as deleting and posting again until we have proper message edition.

Its working?

synapse.config.appservice - 78 - INFO - - Loaded application service: ApplicationService: {'sender': '@TelegramBot:matrix.allvips.xyz', 'url': 'http://localhost:8443', 'rate_limited': True, 'hs_token': '821e19543fcd4538e95bff0e2119', 'token': '51f53afe3aa847e091a3cb797b68135edb', 'namespaces': {'aliases': [], 'rooms': [], 'users': [{'regex': <_sre.SRE_Pattern object at 0x7f1ae05554f0>, 'exclusive': True}]}, 'id': 'telegram', 'protocols': set([])}

[24/Jul/2017:12:19:32 +0000] "PUT /transactions/345?access_token= HTTP/1.1" 200 2 "-" "Synapse/0.22.1"

no bot @TelegramBot

TypeError: client.messages.getFullChat is not a function

user_mk_portal consistently fails with the following stack trace:

TypeError: client.messages.getFullChat is not a function
at _getClient.then (…/lib/TelegramGhost.js:307:33)
at tryCatcher (…/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (…/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (…/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromiseCtx (…/node_modules/bluebird/js/release/promise.js:606:10)
at Async._drainQueue (…/node_modules/bluebird/js/release/async.js:138:12)
at Async._drainQueues (…/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (…/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:672:20)
at tryOnImmediate (timers.js:645:5)
at processImmediate [as _immediateCallback] (timers.js:617:5)

Failed to join room

When trying to invite @telegrambot:DOMAIN I get this error

telegram-bridge    | ::ffff:172.18.0.6 - - [07/Nov/2017:15:45:50 +0000] "PUT /transactions/11?access_token=<REDACTED> HTTP/1.1" 200 2 "-" "Synapse/0.24.1"
telegram-bridge    | 
telegram-bridge    | [-] POST synapse:8008/_matrix/client/r0/join/!<ROOMID>%3A<DOMAIN> (AS) Body: {}
telegram-bridge    | [-] POST synapse:8008/_matrix/client/r0/join/!<ROOMID>%3A<DOMAIN> (AS) HTTP null Error: {}
telegram-bridge    | Failed:  Error: Failed to join room
telegram-bridge    |     at /app/node_modules/matrix-appservice-bridge/lib/components/intent.js:491:26
telegram-bridge    |     at _rejected (/app/node_modules/q/q.js:864:24)
telegram-bridge    |     at /app/node_modules/q/q.js:890:30
telegram-bridge    |     at Promise.when (/app/node_modules/q/q.js:1142:31)
telegram-bridge    |     at Promise.promise.promiseDispatch (/app/node_modules/q/q.js:808:41)
telegram-bridge    |     at /app/node_modules/q/q.js:624:44
telegram-bridge    |     at runSingle (/app/node_modules/q/q.js:137:13)
telegram-bridge    |     at flush (/app/node_modules/q/q.js:125:13)
telegram-bridge    |     at _combinedTickCallback (internal/process/next_tick.js:73:7)
telegram-bridge    |     at process._tickCallback (internal/process/next_tick.js:104:9)
telegram-bridge    | Error: Failed to join room
telegram-bridge    |     at /app/node_modules/matrix-appservice-bridge/lib/components/intent.js:491:26
telegram-bridge    |     at _rejected (/app/node_modules/q/q.js:864:24)
telegram-bridge    |     at /app/node_modules/q/q.js:890:30
telegram-bridge    |     at Promise.when (/app/node_modules/q/q.js:1142:31)
telegram-bridge    |     at Promise.promise.promiseDispatch (/app/node_modules/q/q.js:808:41)
telegram-bridge    |     at /app/node_modules/q/q.js:624:44
telegram-bridge    |     at runSingle (/app/node_modules/q/q.js:137:13)
telegram-bridge    |     at flush (/app/node_modules/q/q.js:125:13)
telegram-bridge    |     at _combinedTickCallback (internal/process/next_tick.js:73:7)
telegram-bridge    |     at process._tickCallback (internal/process/next_tick.js:104:9)
telegram-bridge    | ::ffff:172.18.0.6 - - [07/Nov/2017:15:46:12 +0000] "PUT /transactions/12?access_token=<REDACTED> HTTP/1.1" 200 2 "-" "Synapse/0.24.1"

Cannot find module 'telegram-mtproto'

When I trying to generate registration or start application i get this:

# node index.js --generate-registration -f telegram-registration.yaml  -u localhost
/app/node_modules/olm/olm.js:19
"undefined"!==typeof module&&(module.exports=a);process.on("uncaughtException",function(a){if(!(a instanceof T))throw a;});a.inspect=function(){return"[Emscripten Module object]"}}else if(ma)a.print||(a.print=print),"undefined"!=typeof printErr&&(a.printErr=printErr),a.read="undefined"!=typeof read?read:function(){throw"no read() available (jsc?)";},a.readBinary=function(a){if("function"===typeof readbuffer)return new Uint8Array(readbuffer(a));a=read(a,"binary");z("object"===typeof a);return a},"undefined"!=
                                                                                                                ^

Error: Cannot find module 'telegram-mtproto'
    at Function.Module._resolveFilename (module.js:470:15)
    at Function.Module._load (module.js:418:25)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/app/lib/TelegramGhost.js:5:15)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/app/lib/MatrixUser.js:3:21)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/app/lib/Main.js:11:18)
    at Module._compile (module.js:571:32)
# node -v
v7.10.0

# npm -v
4.2.0

npm install log cut

UNMET PEER DEPENDENCY webpack@>=0.9 <2 || ^2.1.0-beta || ^2.2.0

npm WARN [email protected] requires a peer of webpack@>=0.9 <2 || ^2.1.0-beta || ^2.2.0 but none was installed.

So it is seems to be telegram-mtproto bug.
I can see "telegram-mtproto": "leonerd/telegram-mtproto#cf17f2b" in package.json so there is need to change this after telegram-mtproto fix.

Can not start or generate registration

matrix@matrix:/opt/tgr/matrix-appservice-tg$ node index.js --generate-registration -f telegram-registration.yaml -u localhost:9938
/opt/tgr/matrix-appservice-tg/lib/TelegramGhost.js:181
remove: (...keys) => {
^^^

SyntaxError: Unexpected token ...
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object. (/opt/tgr/matrix-appservice-tg/lib/MatrixUser.js:3:21)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object. (/opt/tgr/matrix-appservice-tg/lib/Main.js:12:18)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object. (/opt/tgr/matrix-appservice-tg/index.js:4:12)

Cannot create portal

telegram-bridge    | ::ffff:172.18.0.6 - - [08/Nov/2017:17:24:43 +0000] "PUT /transactions/117?access_token=<REDACTED> HTTP/1.1" 200 2 "-" "Synapse/0.24.1"
telegram-bridge    | 
telegram-bridge    | Admin: user_mk_portal <TELEGRAM USERNAME> <CHANNEL ID> --access_hash=<ACCESS HASH (without #??)> --peer_type=channel
telegram-bridge    | access_hash: <Buffer>
telegram-bridge    | getting users from store
telegram-bridge    | got user store result []
telegram-bridge    | putRoom finished
telegram-bridge    | done creating portal
telegram-bridge    | got user
telegram-bridge    | got ghost
telegram-bridge    | INIT
telegram-bridge    | ghost: got client
telegram-bridge    | ghost: type channel
telegram-bridge    | REQUEST
telegram-bridge    | AUTH
telegram-bridge    | WORK
telegram-bridge    | REQUEST
telegram-bridge    | AUTH
telegram-bridge    | AUTH
telegram-bridge    | WORK
telegram-bridge    | WORK
telegram-bridge    | REQUEST
telegram-bridge    | REQUEST
telegram-bridge    | REQUEST
telegram-bridge    | REQUEST
telegram-bridge    | AUTH

I added in some console statements to the above to try and pinpoint where the issue is. Looks like it's here. Once the call to the telegram-mtproto client gets called, I get a never ending stream of REQUEST, AUTH, and WORK in the logs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.