Wechaty: delay time for all function(method) that calls Tencent API

Created on 22 Jun 2017  ·  4Comments  ·  Source: wechaty/wechaty

Since many people recently experiencing blocking from wechat web login.
The problem is when wechaty being scan, then the error message "Your login may be compromised. For account security, you cannot log in to Web WeChat. You can try mobile WeChat or Windows WeChat." pop-up. This issue is related previous found https://github.com/Chatie/wechaty/wiki/Throttled-Rate-for-WeChat-Web-API

Therefore, we should protect user that using wechaty. My idea is add all sayable, and set alias name function a delay base on how many character in a string, and each character delay 0.5s for assume is a tying time. maybe also add some more random seconds(0~5s) on top of that for more nature typing
For example, contact.say("Hello") or room.say("Hello") are 5 characters, so 5 * 0.5s = 2.5s (2500ms) + some random seconds to delay send out this message.

We should include this into all of related function.

enhancement help wanted

Most helpful comment

Hi, @kis87988 , that's a very good proposal.

Here's another study of the rate limit of Tencent API: https://wxpy.readthedocs.io/zh/latest/utils.html#id7

I suggest you write a document for this, describing all case about this, and give the suggestion delay with your algorithm, and let the community discuss it, with code snip examples. (The Wiki Page you provided above should be a good place to do that)

To do this is because:

  1. We are not sure what's the best algorithm to work with Tencent API.
  2. There's other APIs also need to be throttled, like FriendRequest.add(), Room.add() etc.
  3. We can not force the developer to wait because of Async of Node unless they are always using await

Hope we could include this into all of the related function in the future release of Wechaty with your help.

Thanks!

All 4 comments

Hi, @kis87988 , that's a very good proposal.

Here's another study of the rate limit of Tencent API: https://wxpy.readthedocs.io/zh/latest/utils.html#id7

I suggest you write a document for this, describing all case about this, and give the suggestion delay with your algorithm, and let the community discuss it, with code snip examples. (The Wiki Page you provided above should be a good place to do that)

To do this is because:

  1. We are not sure what's the best algorithm to work with Tencent API.
  2. There's other APIs also need to be throttled, like FriendRequest.add(), Room.add() etc.
  3. We can not force the developer to wait because of Async of Node unless they are always using await

Hope we could include this into all of the related function in the future release of Wechaty with your help.

Thanks!

  1. I'd like to suggest to use RxJS to do the throttle job in deep, e.g. inside PuppetWebBridge class, which all API calls will go through.

Class PuppetWebBridge: https://github.com/Chatie/wechaty/blob/master/src/puppet-web/bridge.ts

  1. Consider using RxJS to implement a throttled module by separating observable values by specific amount of time in RxJS

Here's an example: Time shifts the observable sequence based on a subscription delay and a delay selector function for each element.

var source = Rx.Observable
  .range(0, 3)
  .delay(function (x) { return Rx.Observable.timer(x * 400); })
  .timeInterval()
  .map(function (x) { return x.value + ':' + x.interval; });

var subscription = source.subscribe(
  function (x) {
    console.log('Next: %s', x);
  },
  function (err) {
    console.log('Error: %s', err);
  },
  function () {
    console.log('Completed');
  });

// => Next: 0:0
// => Next: 1:400
// => Next: 2:400
// => Completed

However, if you have other good ideas or methods, please feel free to share and let's discuss about them.

@kis87988 @Gcaufy @xinbenlv I just finished a RxJS Queue module at here: https://github.com/zixia/rx-queue, which could solve this issue very clean and effective.

Please let me know if you have any thoughts about it. Thanks!

Merge to #1305

Was this page helpful?
0 / 5 - 0 ratings