Git Product home page Git Product logo

Comments (7)

mekpavit avatar mekpavit commented on July 17, 2024 1

I've already tested the dialogflow-integration with Twitter's direct message. I found out, that when you deploy dialogflow-integration to Cloud Run, there is a chance, that it will not work! That is, because your dialogflow-integration on Cloud Run fail the Twitter's specification for webhook (Webhook must respond back to Twitter request within 3 seconds).

Here's what happens when you deploy dialogflow-integration to Cloud Run:

  1. dialogflow-integration sends a POST request to Twitter API to delete any subscriptions on your Twitter Account
  2. dialogflow-integration sends a POST request to Twitter API to delete any registered webhooks on your Twitter Account
  3. dialogflow-integration sends a POST request to Twitter API to register a new webhook url (the webhook url specified in targetUrl variable) to your Twitter app
    3.1 Twitter sends a GET request to your dialogflow-integration to make sure that your web app supports POST requests for incoming events
    3.2 If your dialogflow-integration responds Twitter request within 3 seconds, your webhook url will be registered. **If not, the webhook will not be registered (this might be the reason why your dialogflow-integration did not work!)
  4. dialogflow-integration sends a POST request to Twitter API to register a subscription to your Twitter app --> If (3) fails, this will fail as well.

In order to solve your issue, I suggest you to:

  1. Replace registerWebhook function in /twitter/server.js with the following code
function registerWebhook() {
  return new Promise((resolve, reject) => {
    request.post('https://api.twitter.com/1.1/account_activity/all/'+
        environmentName+'/webhooks.json',{
      oauth:twitterOAuth,
      form:{
        url:targetUrl
      }
    }, function(err, resp, body){
      if (err) {
        console.error('Failed to register webhook: ' + err);
        reject();
      } else {
        // to check the webhook registration result from Cloud Run console
        console.log("register webhook: ", JSON.stringify(resp.body))
        resolve();
      }
    });
  });
}

Note: This code has the same function as the original registerWebhook, except it will also print the response from the Twitter to Cloud Run log.

  1. Re-deploy your dialogflow-integration to Cloud Run

  2. Check the log console. If you see the following message, try to re-deploy your dialogflow-integration again!

register webhook: "{\"errors\":[{\"code\":214,\"message\":\"High latency on CRC GET request. Your webhook should respond in less than 3 seconds.\"}]}"

Hope this solves your problem!

from dialogflow-integrations.

JyothishG avatar JyothishG commented on July 17, 2024 1

@mekpavit Thanks for the help. I added the log as you suggested and it shows the below error message:

register webhook: "{"errors":[{"code":214,"message":"Too many resources already created."}]}"

from dialogflow-integrations.

mekpavit avatar mekpavit commented on July 17, 2024 1

@JyothishG Instead of using URL from ngrok, you can just use http://127.0.01:5000/ as a callback URL.

Try this one

  1. Add these 2 callback URL to your Twitter app
    http://127.0.0.1:5000/callbacks/addsub
    http://127.0.0.1:5000/callbacks/removesub

  2. Access your local dashboard using http://127.0.0.1:5000/

  3. Try adding/removing subscription and webhook

from dialogflow-integrations.

mekpavit avatar mekpavit commented on July 17, 2024

I am now trying to reproduce your issue. If there is any progress, I will tell you here!

from dialogflow-integrations.

mekpavit avatar mekpavit commented on July 17, 2024

@JyothishG I suggest you to use the Twitter Activity Dashboard to see all the webhook registered to your account. I guess that maybe you have too many active webhook/subscription on your Twitter Dev account. I'm not sure because I don't get used to Twitter API that much. But I think you should try to register the webhook and subscription to the dashboard instead, so we can make sure that the problem doesn't come from dialogflow-integration source code.

So, could you please try to register the webhook/subscription directly via the dashboard and share the upcoming result?

from dialogflow-integrations.

JyothishG avatar JyothishG commented on July 17, 2024

@mekpavit When I tried to deploy the twitter activity dashboard application to Heroku like the instructions, it fails to launch the application. I'm always getting this error in the Heroku logs:
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

When tried in the local environment, it runs but the second step in "Configure webhook to receive events" fails (ie, Add a user subscription). It says:

Callback URL not approved for this client application. Approved callback URLs can be adjusted in your application settings

I'm using ngrok to tunnel the requests and added the callback URLs to the application settings on the twitter developer page.

I'm really stuck here.

from dialogflow-integrations.

oort7 avatar oort7 commented on July 17, 2024

I was able to register webhook url using Twitter Activity Dashboard - I also got several errors (high latency, too many resources) but after several attempts it was registered. In the next step it needs to be validated. I have disabled Twitter integration in Dialogflow and now it works through deployed container. Thanks!

from dialogflow-integrations.

Related Issues (20)

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.