Skip to content

Commit

Permalink
on_behalf_of seems to work now
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Sep 27, 2018
1 parent 8510788 commit ea7f89e
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 145 deletions.
10 changes: 1 addition & 9 deletions build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,7 @@ rm -f $GOPATH/bin/init-db
# Build chatbot release
echo "Building python code..."

pushd ./py_grpc > /dev/null

# Generate version file from git tags
python3 version.py

# Generate tinode-grpc package
python3 setup.py -q sdist bdist_wheel

popd > /dev/null
./build-py-grpc.py

# Release chatbot
echo "Packaging chatbot.py..."
Expand Down
4 changes: 2 additions & 2 deletions chatbot/python/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tinode Chatbot Example
# Tinode Chatbot

This is a rudimentary chatbot for Tinode using [gRPC API](../../pbx/). It's written in Python as a demonstration
This is a simple chatbot for Tinode using [gRPC API](../../pbx/). It's written in Python as a demonstration
that the API is language-independent.

The chat bot subscribes to events stream using Plugin API and logs in as a regular user. The event stream API is used to listen for creation of new accounts. When a new account is created, the bot initiates a p2p topic with the new user. Then it listens for messages sent to the topic and responds to each with a random quote from `quotes.txt` file.
Expand Down
14 changes: 8 additions & 6 deletions pbx/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# Protocol Buffer and gRPC definitions

Definitions for [gRPC](https://grpc.io/) client and plugins.
Definitions for Tinode [gRPC](https://grpc.io/) client and plugins.

gRPC clients must implement rpc service `Node`, plugins `Plugin`.
Tinode gRPC clients must implement rpc service `Node`, Tinode plugins `Plugin`.

Generated `Go` and `Python` code is included. For a sample `Python` implementation of a command line client see [tn-cli](../tn-cli/).
Generated `Go` and `Python` code is included. For a sample `Python` implementation of a command line client see [tn-cli](../tn-cli/).
For a partial plugin implementation see [chatbot](../chatbot/).

If you want to make changes, you have to install protobuffers tool chain and gRPC. To generate `Go` bindings add the following comment to your code and run `go generate` (your actual path to `/pbx` may be different):
If you want to make changes, you have to install protobuffers tool chain and gRPC:
```
$ python -m pip install grpcio grpcio-tools googleapis-common-protos
```

To generate `Go` bindings add the following comment to your code and run `go generate` (your actual path to `/pbx` may be different):
```
//go:generate protoc --proto_path=../pbx --go_out=plugins=grpc:../pbx ../pbx/model.proto
```

To generate `Python` bindings:

```
python -m grpc_tools.protoc -I../pbx --python_out=. --grpc_python_out=. ../pbx/model.proto
```

4 changes: 3 additions & 1 deletion pbx/generate-python.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash

# This generates
# This generates python gRPC bindings for Tinode.
python -m grpc_tools.protoc -I../pbx --python_out=../py_grpc/tinode_grpc --grpc_python_out=../py_grpc/tinode_grpc ../pbx/model.proto
# Bindings are incompatible with Python packaging system. This is a fix.
python py_fix.py
196 changes: 111 additions & 85 deletions py_grpc/tinode_grpc/model_pb2.py

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions server/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,10 @@ func (t *Topic) run(hub *Hub) {
func (t *Topic) handleSubscription(h *Hub, sreg *sessionJoin) error {
asUid := types.ParseUserId(sreg.pkt.from)

msgsub := sreg.pkt.Sub
getWhat := 0
if sreg.pkt.Get != nil {
getWhat = parseMsgClientMeta(sreg.pkt.Get.What)
if msgsub.Get != nil {
getWhat = parseMsgClientMeta(msgsub.Get.What)
}

if err := t.subCommonReply(h, sreg, (getWhat&constMsgMetaDesc != 0)); err != nil {
Expand Down Expand Up @@ -705,7 +706,7 @@ func (t *Topic) handleSubscription(h *Hub, sreg *sessionJoin) error {

if getWhat&constMsgMetaSub != 0 {
// Send get.sub response as a separate {meta} packet
if err := t.replyGetSub(sreg.sess, asUid, sreg.pkt.id, sreg.pkt.Get.Sub); err != nil {
if err := t.replyGetSub(sreg.sess, asUid, sreg.pkt.id, msgsub.Get.Sub); err != nil {
log.Printf("topic[%s] handleSubscription Get.Sub failed: %v", t.name, err)
}
}
Expand All @@ -719,14 +720,14 @@ func (t *Topic) handleSubscription(h *Hub, sreg *sessionJoin) error {

if getWhat&constMsgMetaData != 0 {
// Send get.data response as {data} packets
if err := t.replyGetData(sreg.sess, asUid, sreg.pkt.id, sreg.pkt.Get.Data); err != nil {
if err := t.replyGetData(sreg.sess, asUid, sreg.pkt.id, msgsub.Get.Data); err != nil {
log.Printf("topic[%s] handleSubscription Get.Data failed: %v", t.name, err)
}
}

if getWhat&constMsgMetaDel != 0 {
// Send get.del response as a separate {meta} packet
if err := t.replyGetDel(sreg.sess, asUid, sreg.pkt.id, sreg.pkt.Get.Del); err != nil {
if err := t.replyGetDel(sreg.sess, asUid, sreg.pkt.id, msgsub.Get.Del); err != nil {
log.Printf("topic[%s] handleSubscription Get.Del failed: %v", t.name, err)
}
}
Expand Down
4 changes: 4 additions & 0 deletions tn-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ The client takes optional parameters:
* `--login-cookie` direct the client to read the token from the cookie file generated during an earlier login.

If multiple `login-XYZ` are provided, `login-cookie` is considered first, then `login-token` then `login-basic`. Authentication with token (and cookie) is much faster than with the username-password pair.

## Crash on shutdown

Python 3 sometimes crashes on shutdown with a message `Fatal Python error: PyImport_GetModuleDict: no module dictionary!`. That happens because it's buggy: https://bugs.python.org/issue26153
Loading

0 comments on commit ea7f89e

Please sign in to comment.