Integration of Tinode in an existing project

1,270 views
Skip to first unread message

radazul...@gmail.com

unread,
May 7, 2020, 1:14:14 PM5/7/20
to Tinode General
Is there a way to integrate Tinode in an existing website with it's own users database, groups, avatars, names, etc? I really don't understand.

I need something like this:

- user registers on the website and the registration script (php) automatically creates a new user in the messenger.
- user logins to the website and when access the section "Messages" (tinode) he is automatically logged in to the messenger without a need to enter username/password.
- user registration and creating of groups and many other functions are disabled in the messenger and only is possible from the website
- user changes his avatar on the website and new avatar appears in the messenger
- user sends a message to another user from a form on the profile (without opening messenger) and this message automatically goes to Tinode and new contact is automatically added to the recipient in Tinode
- user deleted his profile on the website and the same user is deleted fom Tinode
etc, etc

Can this be done from a php script?

I was thinking that I will be able to create/delete users groups just by inserting/deleting data in Tinode's MySQL database.

I was thinking that I can download Tinode web app and just remove things like user registration, creating of new groups, etc and create/delete users just by inserting/deleting data in Tinode's MySQL database. But then I used Docker to install Tinode and now when I access any of my domains:
appears Tinode messenger's interface, the same as the web app, with all the functions - user registration/groups creation, etc. How do I deactivate it? I want only the web app and mobile messangers but not Tinode's chat accessing address https://domain1:6060 which I can not even edit.

If it's not possible, I just have to forget about Tinode.

Thanks.


ge...@letsopen.co

unread,
May 7, 2020, 2:11:26 PM5/7/20
to Tinode General
On Thursday, May 7, 2020 at 8:14:14 PM UTC+3, radazul...@gmail.com wrote:
Is there a way to integrate Tinode in an existing website with it's own users database, groups, avatars, names, etc? I really don't understand.

I need something like this:

- user registers on the website and the registration script (php) automatically creates a new user in the messenger.

 
- user logins to the website and when access the section "Messages" (tinode) he is automatically logged in to the messenger without a need to enter username/password.

You can write your own authenticator which, for example, uses shared cookies for authentication.
You can generate auth tokens and save them to localStore where they can be picked up by Tinode webapp.
 
- user registration and creating of groups and many other functions are disabled in the messenger and only is possible from the website

 
- user changes his avatar on the website and new avatar appears in the messenger

 
- user sends a message to another user from a form on the profile (without opening messenger) and this message automatically goes to Tinode and new contact is automatically added to the recipient in Tinode

 
- user deleted his profile on the website and the same user is deleted fom Tinode

 
etc, etc

Can this be done from a php script?

I was thinking that I will be able to create/delete users groups just by inserting/deleting data in Tinode's MySQL database.

That's not a good idea.

radazul...@gmail.com

unread,
May 27, 2020, 5:10:36 AM5/27/20
to Tinode General
Thank you for your reply.


I saw tni-cli, however I can not understand how can I use it.

My website is on server A but I am going to run Tinode+Tinode's database on server B. When user creates account on server A, I want to run some script to create the same account on server B (in Tinode).
The same with deleting, updation user information, etc.


As I understand, the only way is to send a CURL request from server A to a PHP script with Python commands located on server B. But in this case I should enable shell_exec() in PHP on server B and this is not a good idea.

Am I missing something?

Gene

unread,
May 27, 2020, 5:22:07 AM5/27/20
to Tinode General
Given your questions, I suspect you did not read or understand the references I have provided in my original answer. Why don't you read them first and then ask specific questions which would show that you had done your homework?

Thanks.

radazul...@gmail.com

unread,
Jun 10, 2020, 4:06:27 PM6/10/20
to Tinode General
Thank you for your reply. Sorry, I didn't read all the documentation, it's clear now.

Soy yo

unread,
Oct 23, 2020, 7:14:39 AM10/23/20
to Tinode General
I have installed tn-cli and  tinode_grpc  but really don't understand how do I perfom actions from server A where website is located to server B where Tinode is running.
Can anyone give me some example?
I need to delete users, create group topics and add subscribe users, send messages as root from user a to user B...

Can I do it by sending a curl request from php? If yes, to which URL?
 My Tinode conf. contains: "grpc_listen": ":16060", however if I try to access: https://domain:16060 I get  ERR_HTTP2_PROTOCOL_ERROR  

Gene

unread,
Oct 23, 2020, 1:35:35 PM10/23/20
to Tinode General
On Friday, October 23, 2020 at 4:14:39 AM UTC-7 Soy yo wrote:
I have installed tn-cli and  tinode_grpc  but really don't understand how do I perfom actions from server A where website is located to server B where Tinode is running.
Can anyone give me some example?

Here are examples of basic management tasks performed with tn-cli
 
I need to delete users, create group topics and add subscribe users, send messages as root from user a to user B...

Can I do it by sending a curl request from php? If yes, to which URL?

It's gRPC. You can add another layer in the form of http calls but you don't need to. 
curl issues HTTP requests, tn-cli issues gRPC calls. You can also call gRPC directly from PHP. 
 
 My Tinode conf. contains: "grpc_listen": ":16060", however if I try to access: https://domain:16060 I get  ERR_HTTP2_PROTOCOL_ERROR  

It's gRPC. You need to use a gRPC client. If your code is in PHP then start here: https://grpc.io/docs/languages/php/quickstart/

Soy yo

unread,
Oct 24, 2020, 10:56:12 AM10/24/20
to Tinode General
netstat -ltnp | grep -w ':16060' 
tcp6       0      0 :::16060                :::*                    LISTEN      5793/./tinode


But when I try to run the command line   python tn-cli.py --login-basic=alice:alice123 appears this:


python tn-cli.py --login-basic=alice:alice123
Tinode command line client. Version 1.5.1/0.16.7; gRPC/1.32.0.
Server at 'localhost:16060'
Logging in with login:password alice:alice123
gRPC failed with StatusCode.UNAVAILABLE: failed to connect to all addresses
Shutting down...



Gene

unread,
Oct 24, 2020, 12:59:28 PM10/24/20
to Tinode General
It looks like you have some kind of network problem. It works for me:

$ python3 ./tn-cli.py
Tinode command line client. Version 1.5.2/0.16.8; gRPC/1.19.0; Python 3.7.2. 
Server at 'localhost:16060'
Logging in with cookie file
Missing or invalid cookie file '.tn-cli-cookie' [Errno 2] No such file or directory: '.tn-cli-cookie'
<= Connected to server: maxFileUploadSize: 8388608; maxTagLength: 96; maxTagCount: 16; ver: 0.16; minTagLength: 2; maxMessageSize: 262144; maxSubscriberCount: 32; build: rethinkdb:undef
<= 201 created
tn>

The only material difference I see is gRPC/1.19.0 vs gRPC/1.32.0.

Gene

unread,
Oct 24, 2020, 1:06:34 PM10/24/20
to Tinode General
Upgraded to the latest gRPC, still works fine:

$ python3 ./tn-cli.py
Tinode command line client. Version 1.5.2/0.16.8; gRPC/1.33.1; Python 3.7.2.
Server at 'localhost:16060'
Logging in with cookie file
Missing or invalid cookie file '.tn-cli-cookie' [Errno 2] No such file or directory: '.tn-cli-cookie'
<= Connected to server: maxMessageSize: 262144; minTagLength: 2; maxSubscriberCount: 32; build: rethinkdb:undef; maxFileUploadSize: 8388608; maxTagLength: 96; maxTagCount: 16; ver: 0.16
<= 201 created

Soy yo

unread,
Oct 25, 2020, 10:13:44 AM10/25/20
to Tinode General
I just installed Tinode on a new server. Debian 10 Buster. No firewall set up, nothing. But still I am getting the same error:

gRPC failed with StatusCode.UNAVAILABLE: failed to connect to all addresses

python tn-cli.py --login-basic=alice:alice123
Tinode command line client. Version 1.5.1/0.16.7; gRPC/1.33.1.
Server at 'localhost:16060'
Logging in with login:password alice:alice123
gRPC failed with StatusCode.UNAVAILABLE: failed to connect to all addresses
Shutting down...
Traceback (most recent call last):
  File "tn-cli.py", line 1119, in <module>
    run(args, schema, secret)
  File "tn-cli.py", line 1000, in run
    tn_globals.InputThread.join(0.3)
  File "/usr/lib/python2.7/threading.py", line 929, in join
    raise RuntimeError("cannot join thread before it is started")
RuntimeError: cannot join thread before it is started



Message has been deleted

Gene

unread,
Oct 25, 2020, 12:39:19 PM10/25/20
to Tinode General
On Sunday, October 25, 2020 at 7:13:44 AM UTC-7 Soy yo wrote:
I just installed Tinode on a new server. Debian 10 Buster. No firewall set up, nothing. But still I am getting the same error:

gRPC failed with StatusCode.UNAVAILABLE: failed to connect to all addresses

If I had to guess, your server is probably not listening on localhost:16060. It's listening on something else, like my-host:16060. 

Soy yo

unread,
Oct 25, 2020, 2:05:42 PM10/25/20
to Tinode General

lsof -i
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
tinode  2894 debian    6u  IPv6  28530      0t0  TCP localhost:37128->localhost:mysql (ESTABLISHED)
tinode  2894 debian    8u  IPv4  29043      0t0  TCP localhost:16060 (LISTEN)
tinode  2894 debian    9u  IPv6  23509      0t0  TCP *:6060 (LISTEN)

Gene

unread,
Oct 25, 2020, 5:05:57 PM10/25/20
to Tinode General
Google for it:

For example, try this: 
This is your installation, so debug it.

Soy yo

unread,
Oct 28, 2020, 1:06:04 PM10/28/20
to Tinode General
There were several problems.

1. Nginx running on port 80. Nginx was already running before I installed Tinode and it looked that there are no problems. But I was not able to restart Nginx because of error message saying that another service is listening to port 80. I just changed Nginx port number to 8080.
2. While experimenting I changed  the "listen" value in tinode.conf to "listen": "localhost:6060". It allows to start Tinoe but in my case I was not able to login from the web app (I didn't test the mobile apps) - Connection failed: 503. So, I had to change it back to: "listen": ":6060"
3. I was not able to make grpc calls because I started Tinode with:
./tinode &
If I start Tinode with:
sudo ./tinode &
everything works fine. I guess it's a permission issue of Letsencrypt files or folders. If somedoby knows correct permissions so that it's possible to start Tinode without sudo, please let me know.
4. I was making grcp call without ssl flag as in the ducumentation:
python tn-cli.py --login-basic=alice:alice123 
it didn't work. This works:
python tn-cli.py --host=127.0.0.1:16060 --web-host=127.0.0.1:6060 --ssl --ssl-host=example.domain --login-basic=alice:alice123

More questions on grpc calls.

1) Sending messages as root user

Documentation says:
it allows the root user to send messages on behalf of other users 

Can somebody give me example of grpc call how do I send a messge from user A to user B as a root user C? 

2) Can root user create group topics on behalf of other users and subscribe users to the created group topics?
An example would be appreciated.

Thanks.
 


Gene S

unread,
Oct 28, 2020, 3:07:06 PM10/28/20
to tinode
On Wed, Oct 28, 2020 at 10:06 AM Soy yo <radazul...@gmail.com> wrote:
There were several problems.

1. Nginx running on port 80. Nginx was already running before I installed Tinode and it looked that there are no problems. But I was not able to restart Nginx because of error message saying that another service is listening to port 80. I just changed Nginx port number to 8080.

You can run multiple web servers behind Nginx. Take a look at the proxy_pass directive. That's how we set up our sandbox.tinode.co and web.tinode.co
 
2. While experimenting I changed  the "listen" value in tinode.conf to "listen": "localhost:6060". It allows to start Tinoe but in my case I was not able to login from the web app (I didn't test the mobile apps) - Connection failed: 503. So, I had to change it back to: "listen": ":6060"

You need to reload the app after changing the port on the server.
 
3. I was not able to make grpc calls because I started Tinode with:
./tinode &
If I start Tinode with:
sudo ./tinode &
everything works fine. I guess it's a permission issue of Letsencrypt files or folders. If somedoby knows correct permissions so that it's possible to start Tinode without sudo, please let me know. 
4. I was making grcp call without ssl flag as in the ducumentation:
python tn-cli.py --login-basic=alice:alice123 
it didn't work. This works:
python tn-cli.py --host=127.0.0.1:16060 --web-host=127.0.0.1:6060 --ssl --ssl-host=example.domain --login-basic=alice:alice123

More questions on grpc calls.

1) Sending messages as root user

Documentation says:
it allows the root user to send messages on behalf of other users 

Can somebody give me example of grpc call how do I send a messge from user A to user B as a root user C? 


2) Can root user create group topics on behalf of other users and subscribe users to the created group topics?
An example would be appreciated.

Yes. It works exactly the same way as normal except set on_bahalf_of:
 
--
You received this message because you are subscribed to the Google Groups "Tinode General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tinode+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tinode/d355dab8-75f2-424b-98af-e8130790c4f2n%40googlegroups.com.

Soy yo

unread,
Oct 31, 2020, 9:29:46 AM10/31/20
to Tinode General
I spent already more than 2 days trying to understand GRPC. There are only a few tutorials that lead to nowhere. I even posted a project on Freelancer, got only 6 bids but looks that all the persons submitted bids without reading the project because later noone wanted to do this job.

I stopped to read tutorials and did the following things. Probably everything is wrong, I don't know.

- Installed php grpc extension
- Generated php classes from Tinode's proto file

I attach a file to this post how my files look like. If it's correct, can someone help me and change the index.php file to show the following things:
- connect and authenticate by Tinode's GRPC server with a secure connection as a root user
- create an user account
- delete an user account
- send a message on behalf of root user A from user B to user C.
- create a group as a root user on behalf of another user.

I am willing to pay for it. If it's needed, please leave a message how can I contact you.
But please, I don't need links to tutorials.

Thanks.

El viernes, 23 de octubre de 2020 a las 18:35:35 UTC+1, Gene escribió:
grpc1.zip

Gene

unread,
Oct 31, 2020, 2:04:48 PM10/31/20
to Tinode General
On Saturday, October 31, 2020 at 6:29:46 AM UTC-7 Soy yo wrote:
I spent already more than 2 days trying to understand GRPC. There are only a few tutorials that lead to nowhere. I even posted a project on Freelancer, got only 6 bids but looks that all the persons submitted bids without reading the project because later noone wanted to do this job.

I stopped to read tutorials and did the following things. Probably everything is wrong, I don't know.

- Installed php grpc extension
- Generated php classes from Tinode's proto file

Yes, that's what you are supposed to do.

I attach a file to this post how my files look like. If it's correct, can someone help me and change the index.php file to show the following things:
- connect and authenticate by Tinode's GRPC server with a secure connection as a root user

Why don't you look at python chatbot and tn-cli code? Python is not that different from PHP.

Soy yo

unread,
Nov 2, 2020, 5:33:41 AM11/2/20
to Tinode General
I already looked at this example in go. It uses: 

conn, err := grpc.Dial("localhost:6061", grpc.WithInsecure()) 

to establish connection and then sends "hi" message. 

hi := &pbx.ClientHi{}  

I really don't unerstand how do I establish connection from php. What is the alternative of Go's "Dial"?



Gene

unread,
Nov 2, 2020, 1:16:19 PM11/2/20
to Tinode General

Marc Lewis

unread,
Mar 21, 2022, 10:37:06 PM3/21/22
to Tinode General
I'm at the exact place you are right now. It looks like you managed to get it working in more recent threads. Can you share any insights in how you got this working? I'm sure once I get the basic connection down that it will all "click" but right now I'm having a hard time finding the missing puzzle pieces.

On Monday, November 2, 2020 at 2:33:41 AM UTC-8 Soy yo wrote:
Reply all
Reply to author
Forward
0 new messages