twitter-lite icon indicating copy to clipboard operation
twitter-lite copied to clipboard

Added Twitter Labs filter stream v1 support

Open btruhand opened this issue 5 years ago • 8 comments

I found the new Twitter Labs filter stream (https://developer.twitter.com/en/docs/labs/filtered-stream/overview) to be more fitting for my use case so I decided to add it as several new function API calls

In detail:

  • added API calls for adding, deleting and getting filter stream rules
  • added stream API call
  • added appropriate types
  • attempted to stick with current code and exporting structure

When I tried to run the tests there are some tests that failed, but doesn't seem to be related to the additions/changes I made:

 FAIL  test/twitter.test.js (9.835s)
  ● rate limits › should get rate limited

    TypeError: Cannot read property '0' of undefined

      141 |           await client.get('help/configuration');
      142 |       } catch (e) {
    > 143 |         expect(e.errors[0]).toHaveProperty('code', 88); // Rate limit exceeded
          |                ^
      144 |         expect(e._headers).toHaveProperty('x-rate-limit-remaining', ['0']);
      145 |       }
      146 |     },

      at Object.<anonymous> (test/twitter.test.js:143:16)

  ● rate limits › should get rate limited

    expect.assertions(4)

    Expected four assertions to be called but received two assertion calls.

      132 |         const response = await client.get('help/configuration');
      133 |         // Since this didn't throw, we'll be running 2 more assertions below
    > 134 |         expect.assertions(4);
          |                ^
      135 |         expect(response).toHaveProperty('photo_sizes');
      136 |         expect(response._headers).toHaveProperty('x-rate-limit-limit', ['15']);
      137 |         let [remaining] = response._headers['x-rate-limit-remaining'];

      at Object.<anonymous> (test/twitter.test.js:134:16)

  ● putting › can update welcome message

    Failed: Object {
      "_headers": Headers {
        Symbol(map): Object {
          "cache-control": [Array],
          "connection": [Array],
          "content-disposition": [Array],
          "content-encoding": [Array],
          "content-length": [Array],
          "content-type": [Array],
          "date": [Array],
          "expires": [Array],
          "last-modified": [Array],
          "pragma": [Array],
          "server": [Array],
          "set-cookie": [Array],
          "status": [Array],
          "strict-transport-security": [Array],
          "x-access-level": [Array],
          "x-connection-hash": [Array],
          "x-content-type-options": [Array],
          "x-frame-options": [Array],
          "x-response-time": [Array],
          "x-transaction": [Array],
          "x-tsa-request-body-time": [Array],
          "x-twitter-response-tags": [Array],
          "x-xss-protection": [Array],
        },
      },
      "errors": Array [
        Object {
          "code": 214,
          "message": "owner must allow dms from anyone",
        },
      ],
    }

      247 |    * and your demo app needs to have access to read, write, and direct messages.
      248 |    */
    > 249 |   it('can update welcome message', async () => {
          |   ^
      250 |     const newWelcomeMessage = await client.post(
      251 |       'direct_messages/welcome_messages/new',
      252 |       {

      at Env.it (node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:89:24)
      at Suite.<anonymous> (test/twitter.test.js:249:3)
      at Object.<anonymous> (test/twitter.test.js:242:1)

I didn't make tests for the filter stream API call itself since I used the current Stream class, but tell me if you want me to still add tests for them (or try to at least test for the query parameters properly being created etc.)

btruhand avatar Jul 24 '20 07:07 btruhand

I need it as well, I hope it's going to be merged. Good job @btruhand !

Cooya avatar Jul 26 '20 22:07 Cooya

We'll merge this, thanks :)

peterpme avatar Jul 29 '20 15:07 peterpme

@peterpme I didn't make documentation changes on the README, would you like me to do that?

btruhand avatar Jul 29 '20 18:07 btruhand

Yes please, thank you!!! Sorry for the delay

peterpme avatar Jul 30 '20 03:07 peterpme

@peterpme been busy, but just pushed the updated README :)

btruhand avatar Aug 01 '20 07:08 btruhand

Hey @btruhand wow this is amazing, thank you so much! are you ready for this to be merged in?

peterpme avatar Aug 18 '20 03:08 peterpme

@peterpme absolutely. From my end there is nothing else I'd like to do, merge whenever you are comfortable with it. I hope it can help pave the way for others to add more Twitter Labs functionalities

Edit: Oh just to make sure, I didn't add to the github workflows pipeline to run the twitter labs related tests (since it uses a different command name). I think I'll leave that to you to decide on when to add it since you will have to opt in to the Twitter Labs functionality

btruhand avatar Aug 20 '20 03:08 btruhand

@peterpme hey peter, just noticed recently that Twitter announced official v2 API for filter stream: https://developer.twitter.com/en/docs/labs/filtered-stream/overview. It's a bit different but would make this PR ineffective

I'll try to find time to modify the PR in the upcoming month or so. Tell me if you want me to remove or retain the withLabs addition

btruhand avatar Sep 06 '20 02:09 btruhand