grokify / ringcentral-permahooks

Webhook proxy to turn RingCentral webhooks into permanent webhooks for use with services like Zapier Instant Triggers.
MIT License
3 stars 0 forks source link

I can't tell if the 'createhook' action is working or not #1

Closed chaismeyer closed 6 years ago

chaismeyer commented 6 years ago

Thank you for this!

I've installed go server locally, setup ngork (it's running successfully), I've modified my credentials and I'm trying to run the go.server file.

I say "Trying" because even though I'm following your instructions nothing is happening after I 'createhook.' http://example.24hrtees.net/olL8

One thing I'm confused about, how do I know if the 'createhook' action is working? Will there be an actual file output somewhere (like to the directory where my ngrok URL is pointing)?

Finally, I noticed that your "MY_URL" example ended with the directory of "/webhook/" I currently have mine (in the .ent file) going to the direct ngrok URL (which ultimately is going to my localhost on my computer) with no additional directories at the end of the URL. Is this accurate?

grokify commented 6 years ago

When you run this can call /createhook it will create log entries like the following showing that it started creating the webhook and successfully received a subscriptionId:

$ go run server.go 
INFO[0023] Creating Hook...                             
INFO[0024] {"eventFilters":["/restapi/v1.0/account/~/extension/~/message-store/instant?type=SMS","/restapi/v1.0/subscription/~?threshold=86400\u0026interval=3600"],"deliveryMode":{"transportType":"WebHook","address":"https://12345678.ngrok.io/webhook"},"expiresIn":604800} 
INFO[0025] Handling webhook...                          
INFO[0025] Validation-Token: 11112222-3333-4444-5555-666677778888
INFO[0025] Created/renewed Webhook with Id: 11112222-3333-4444-5555-666677778888

In the initial version, the URL should be /webhook without a trailing / but I've updated the code to allow a trailing slash and added the above example to the docs.

chaismeyer commented 6 years ago

You're doing a great job helping, thank you! I'm still missing something though.

I made a short video to explain where I'm stuck, hopefully, this will help you understand what I know (very little) and where I might be doing something wrong. https://youtu.be/uyZCU8wwJH8

Any help you can provide is very much appreciated (if you were closer, I'd buy you a beer)!

grokify commented 6 years ago

Hi @chaismeyer,

Thanks for sending the video. It is very helpful and it looks like you have just about everything working. From looking at it, the curl command won't execute because server.go is running as a foreground process which will block any other command from happening, including curl. To get around this for testing purposes, you can:

Running as a background process will return your terminal to a command prompt which will process subsequent commands. You can do this by adding a & to the end like $ go run server.go &. This will return a process ID (aka PID) and return you to the prompt. When running in the foreground, you can stop the process with Control+C. When running in the background, you need to stop the process by killing the PID which you can do with $ kill $PID , e.g. $ kill 12345

Either of these approaches should solve this issue for testing purposes, which these instructions are for.

To run this in production you will want to build a binary and run this as a background process.

Here's more information on foreground and background processes:

https://unix.stackexchange.com/questions/175741/what-is-background-and-foreground-processes-in-jobs

If you want to run this in production, let me know how and I can provide some pointers/instructions on how to do so.

chaismeyer commented 6 years ago

This is great information @grokify, as I had no idea I had to run the curl command in a different terminal window/tab, so thank you for that!

When I do jump into a new tab (after the server's running) and run the curl command, here's the response I get:

terminal-response

Here's the response in the ngrok terminal window:

ngrok

To me, it's acting like it's trying to find a directory called "/createhook" at the location where my ngrok link is pointing, which is my local Mac OSX webserver (on port 80). Here are the folders on my webserver by default:

webserver folders

When I go into my "Documents" folder, this is where I can find my "test.php" file...

webserver php file

...Which is ultimately the file that shows up when I go to my ngrok URL:

webserver file

So I guess my question is, should I have my go server installed inside my webserver directory or do I somehow need to setup my ngork URL to point to my specific folder directory outside of my localhost webserver (not even sure if that's possible)? OR...maybe I'm not even asking the right questions...

Again, you're doing a great job explaining all of this, I'm sorry for the hassle of you not knowing all of the variables on my end.

P.S. I just realized I may not be using github issues appropriately by continuing this 'problem-solving thread' here. If you'd like me to move my questions to stackoverflow.com I'd be glad to do so. :)

grokify commented 6 years ago

Thanks for the screenshots @chaismeyer. They help a lot! It looks like you are running two HTTP servers. By default, ringcentral-permahooks runs on port 8080. You have another local webserver running port 80.

How to tell what port ngrok is forwarding to

From the following ngrok lines, it is configured to forward to your webserver port on 80, not the permahooks app on 8080:

Forwarding                    http://12345678.ngrok.io -> localhost:80
Forwarding                    https://12345678.ngrok.io -> localhost:80

How to connect ngrok to a custom port

To connect ngrok to port 8080 start ngrok with the following:

$ ngrok http 8080

When ngrok runs, you will now see something like the following:

Forwarding                    http://12345678.ngrok.io -> localhost:8080
Forwarding                    https://12345678.ngrok.io -> localhost:8080

This should solve your issue.

How to change the port ringcentral-permahooks uses

You can change the port ringcentral-permahooks runs on by setting the PORT environment variable. PORT is used because this is also used by Heroku. You can set this in the .env file or by adding it to your environment explicitly (e.g. export PORT=80).

You can only have one process listening on a port so if you want permalinks to run on 80 you would need to shut down your other webserver. This won't be necessary if you configure ngrok to use the permalink port.

GitHub vs. Stack Overflow

I think using GitHub issues for this is fine and may be better to resolve this particular issue than Stack Overflow which is more for programming questions than installation/configuration troubleshooting.

chaismeyer commented 6 years ago

Perfect, after changing the port it made ALL the difference when it comes to connecting!

Now I'm having an error message that pops up in the console log: "error: CMN-101"

console-error

Looks like this is the error:

error-codes-doc

Here's a video that shows this (specifically where it errors out): http://example.24hrtees.net/opRb

We're so close I can taste it, I'm just not sure what entries would be considered invalid.

Here's a screenshot of the API Analytics, so we know the connection is happening:

api-analytics

And yes, I'm going to make a complete video tutorial (for newbies like me) explaining how to setup this test for themselves, so that others can avoid the simple mistakes I've made so far. :)

P.S. I noticed that in the .env file, the final URL name is "PERMAHOOKS_MY_URL"

env-url

But in your documentation, I think you may be calling it: "PERMAHOOKS_INBOUND_WEBHOOK_URL"

tunneling-documentation

Unless I'm misunderstanding that they're two different things

grokify commented 6 years ago

Good eyes. The URLs had been updated in the code to be more consistent with each other. The two environment variables are:

You can see this in the code here:

The sample.env file was out of date and I've updated it now which you can see here:

chaismeyer commented 6 years ago

Great, I have the sample.env updated with the new code. After the update and save I ran the curl script and below is what I still get.

I still can't figure out this error, any thoughts on this?

terminal-error
grokify commented 6 years ago

That error indicates that the address isn't being read. It says Parameter [deliveryMode.address] value is invalid and that parameter is not present in the request per the log entry. I've updated the code to report these errors and be more explicit.

You can see this in your long line entry which is missing the address property:

"deliveryMode":{"transportType":"WebHook"}

When the address property is present, you should see something like

"deliveryMode":{"transportType":"WebHook","address":"https://12345678.ngrok.io/webhook"}

You wrote that you updated sample.env. You should update the .env. In the docs you can see this as the following but I'll add additional text to the README.md.

$ cp sample.env .env
$ vi .env

Try setting all the correct variables in the .env file.

For this app, you can alternately specify another .env file by using the ENV_PATH environment variable, but .env in the same directory is the default.

chaismeyer commented 6 years ago

Sorry about that, I typed my previous reply wrong...

I updated the sample.env and the .env to match, then I filled in with the correct credentials and tested. Still getting the same error.

Here is a screenshot of my .env file:

vi env - version 2

Here is a gif of the error I'm getting after the .env is updated with the URL (with the same error despite the URL being in place):

curl-gif

Thanks again for the assistance with this!

grokify commented 6 years ago

Can you update your code and try again. The code's been updated to have better error handling.

Use the the following to update the package:

$ go get -u github.com/grokify/ringcentral-permahooks

This is the entry for the -u flag from the help: go get -h:

The -u flag instructs get to use the network to update the named packages and their dependencies. By default, get uses the network to check out missing packages but does not use it to look for updates to existing packages.

chaismeyer commented 6 years ago

Ok, I updated the code and had an error pop up that said:

error: Your local changes to the following files would be overwritten by merge: .env sample.env Please, commit your changes or stash them before you can merge.

So I googled how to delete my local changes and the winning advice was this: git reset --hard And then... $ git clean -dfx

So I ran those above commands and then updated the package (with no subsequent errors) using: $ go get -u github.com/grokify/ringcentral-permahooks

I copied the sample.env into an ".env" file using this code: $ cp sample.env .env

I edited the template '.env' file (filling in all my information again via "i" for 'insert'), using: $ vi .env saving this file by escaping out of the 'insert' function and saving using: :wq

Then I ran the file (on my already running 'go' server and verifying my ngrok link was operational still - using the 8080 port) using this command: $ curl -XGET 'https://0bf24ac8.ngrok.io/createhook'

Unfortunately, I get the same error message! :( INFO[31182] API Response Err: Status: 400 Bad Request, Body: {"errorCode":"InvalidParameter","message":"Parameter [deliveryMode.address] value is invalid","errors":[{"errorCode":"CMN-101","message":"Parameter [deliveryMode.address] value is invalid","parameterName":"deliveryMode.address"}],"parameterName":"deliveryMode.address"}

Did I miss something? Do I need to shut the server down before updating the files and then start it again after file update?

grokify commented 6 years ago

Can you show the log line with "deliveryMode":{"transportType":"WebHook" in it like you did previously? Earlier, the webhook address wasn't being read so deliveryMode.address was empty which should be caught earlier with this version. It appears that it is not reading in the environment variables properly.

chaismeyer commented 6 years ago

Here's the exact (full error) I'm getting this time:

console-error_v 2

Here's the error I got previous, before the recent code update:

console-error

If I click on the ".env" file and open it in my editor, here's what I see (so I can see the changes are being saved):

code-editor-env-file
grokify commented 6 years ago

That's interesting. What you're showing shouldn't be happening with the latest code. A missing address property indicates that no value is present but there is a check to error out on start up if that is missing.

What do you see for the hash when you type the following from the ringcentral-permahooks directory:

$ git log -n 1

You should see the following commit with some additional info after it.

$ git log -n 1
commit 9d3fed5c112827c5a660eb689c1e6755fea007ce

Can you show everything up to and including Creating Hook.... You should see something like the following:

$ go run server.go 
INFO[0000] Listening on port 8080                       
INFO[0014] [::1]:56537 GET /createhook                  
INFO[0014] Creating Hook...
chaismeyer commented 6 years ago

Ok, here's what I see after running the git log:

git-log

Here's terminal, after I ran everything again just a few minutes ago:

go server-after-update
grokify commented 6 years ago

Okay, that is progress. Your request now has deliveryMode.address populated so the code is working. We just need to update the permissions config on your app as described below. I've also added this to the README.md. I think we're almost there!

The error now says we need to have the SubscriptionWebhook permission:

[SubscriptionWebhook] application permission is required for [WebHook] transport

In the Developer Portal, make sure you have this permission enabled. It is called Webhook Subscriptions in the UI as shown below. I've updated the README.md to indicate the necessary permissions which should also include Read Messages:

ringcentral-permahooks_app_configuration
chaismeyer commented 6 years ago

GREAT! I've finally run the process of creating a webhook successfully, but I don't think I setup my ringcentral app appropriately, according to your updated read.me.

terminal-webhook-success

I tried running the zapier test, but it doesn't find anything so I think the problem are the settings on the ringcentral app.

I'm going to recreate the app, but before I do, what should I choose for this section (since I'm unable to change it after the fact)?

api-type-of-app

I'm planning on having this run on a third party server for the time-being.

Thanks again @grokify, you've been doing a fabulous job working with me and I'm incredibly grateful for your patience!

grokify commented 6 years ago

I'll provide some info on the Zapier test here. I'll respond to the "App Type & Platform" question in the next post.

I tried running the zapier test, but it doesn't find anything so I think the problem are the settings on the ringcentral app.

Try to send a SMS to the phone number. When you do, you should see some log entries like the following.

INFO[0015] 127.0.0.1:56080 POST /webhook                
INFO[0015] Handling webhook...

If you set the log level to debug using log.SetLevel(log.DebugLevel), you should see each incoming message in the logs:

INFO[0007] 127.0.0.1:56165 POST /webhook                
INFO[0007] Handling webhook...                          
DEBU[0007] {"uuid":"3213530895399200455","event":"/restapi/v1.0/account/130709004/extension/130836004/message-store/instant?type=SMS","timestamp":"2018-01-15T21:27:12.702Z","subscriptionId":"7b17e197-b75f-4726-bec2-b15cdf4f78d1","ownerId":"130836004","body":{"id":"3922393004","to":[{"phoneNumber":"+15856234090","name":"Tiger RingForce","location":"Rochester, NY"}],"from":{"phoneNumber":"+17752204114","location":"Sparks / Elko / Fallon / Fernley / Golconda / Incline Village / Pahrump / Spring Creek / Sun Valley / Washoe Valley / Winnemucca / Zephyr Cove, NV"},"type":"SMS","creationTime":"2018-01-15T21:27:12.654Z","lastModifiedTime":"2018-01-15T21:27:12.654Z","readStatus":"Unread","priority":"Normal","attachments":[{"id":"3922393004","type":"Text","contentType":"text/plain"}],"direction":"Inbound","availability":"Alive","subject":"Hello world!","messageStatus":"Received"}} 

After the message is posted to Zapier, if there's an error, you should see a log message starting with the following:

Downstream webhook error:

I'll think about updating this to:

We can keep this issue open a bit longer so you can get it working with Zapier.

grokify commented 6 years ago

Regarding the following issue:

I'm going to recreate the app, but before I do, what should I choose for this section (since I'm unable to change it after the fact)?

api-type-of-app

I'm planning on having this run on a third party server for the time-being.

choose:

Right now, this app will only run as a private app meaning, running with your own RingCentral account. Enhancements are needed to run as a public app where a single app deployment can work with multiple RingCentral accounts.

Running on a 3rd party service is fine and does not affect the above choice.

I've added this to the README.md as well.

chaismeyer commented 6 years ago

It looks like I'm unable to just choose "password flow" (ONLY) as my authorization flow because I'm required to choose a platform type. When I choose a platform type it automatically changes my authorization flows and doesn't allow me to just choose one: auth-flow-platform-type-selection

After I've set everything else up the way I think it needs to be set in the ringcentral app:

rc-app-settings_2 0

Terminal says that everything is working well, but there are no logs being displayed when I send or receive text messages from the phone number (this log was immediately after I sent and received a text from this number/extension).

terminal-webhook-success
grokify commented 6 years ago

The following is fine:

grokify commented 6 years ago

Terminal says that everything is working well, but there are no logs being displayed when I send or receive text messages from the phone number (this log was immediately after I sent and received a text from this number/extension).

If you receive a text, you should get an event and see log entries written. The issue may be the app is listening on a different extension than you are calling. Is your RINGCENTRAL_USERNAME value the same as the phone number you are texting? If not, does the number you are texting to belong to the extension specified by RINGCENTRAL_USERNAME?

chaismeyer commented 6 years ago

Thanks for the reply @grokify

Yes, the RINGCENTRAL_USERNAME is my primary phone number, given to me by RingCentral when I first setup my account. I have a ported number assigned to that same account on the same extension.

I just texted this RINGCENTRAL_USERNAME (primary number), and it did not show up in my ringcentral softphone app, so I tried my other (ported) number in the webhook settings, despite the RingCentral developer app telling me I should use the primary username (which is listed in my "User Account Credentials" section of the developer portal)...the ported number did not work.

I got this message when I tried my ported number in my .env settings:

credentials

It seems to me, that because I'm using my primary username (main phone assigned to my account) in my .env settings, I'm not able to see the text because the text is ultimately going to my ported number.

Here's what I see in my RingCentral Developer account:

different-numbers

You can see that the numbers are different and I'm unable to change the sandbox number to be the same as what the production number would be. Not sure what to do about this.

grokify commented 6 years ago

@chaismeyer

In your screenshot, the left column says Sandbox Environment and the right column says Production Environment. The User Account Credentials including Username and Password are different for the two environments as are the Application Credentials including Client ID, Client Secret and API Server URL.

You cannot change them to be the same right now. You pick the app and user credentials for the environment you are using. For example, during testing, you use "Sandbox Environment" app and user credentials. Here, you will need to login with the Sandbox Environment Username/Password and make enough API calls until you can apply to "Graduate" your app. After you graduate your app, you use the "Production Environment" app and user credentials.

See more here:

https://developer.ringcentral.com/library/getting-started.html

grokify commented 6 years ago

Closing due to inactivity. Please post again if you still have issues.