Hi guys,
I’m looking at Ian’s SMS polling example and can’t seem to get it working.
I’ve set Nexmo’s inbound webhook to the url shown when I launch his app, but still the app doesn’t register my responses.
I’m sure that I am just missing something obvious. The hook I’m using is something like the following:
… .anvilapp.net/version/dev/…//api/sms
ps) I also tried it from a Twillio account but still I do not get any SMS responses. Any help is appreciated.
Al
I’ve not looked at the SMS example (and I can’t seem to find it) so I might be off track here, but I assume you are using an API endpoint based on your snippet.
Can you call the endpoint from a browser or from something like https://resttesttest.com/ ?
Trying to establish if the api is being called and not working or is not being called at all.
Hi David,
I appreciate the help.
Here is the SMS example in case it helps:
Here is the url that is given to me to set as a webhook in Nexmo:
https://iirrkt7nsmnopcv5.anvilapp.net/version/dev/18954cc71c18927c//api/sms
If I understand you correctly, you are asking me to check if the url will simply work if I paste it into a browser or into the site you gave a link to. If so, I get an http error of 0 when using https://resttesttest.com/ and when pasting the url into a browser anvil says “we cant find the app you’re looking for”. If I remove the “_/api/sms” part of the url, then it takes me to the app (but still SMS messages are not being received).
Again, I’m new to this stuff, so I’m sure it is something really simple that I’m just doing incorrectly.
Al
Ok, the API path for your test system should look something like this :
https://N5GEANP7VLC7G6AH.anvilapp.net/_/private_api/MQ3NN26R46UZORDRDWFMXQQF/{name}
If you publish it publicly, it should look something like this :
https://N5GEANP7VLC7G6AH.anvilapp.net/_/api/{name}
Can you try publishing it publicly and see if the end point is reachable then? Make the endpoint simple, ie just return “hello”, just to prove a point.
Sorry David. Could you clarify how to set the endpoint to return “hello”? Are the “{}” for holding parameters? I’m just not understanding how the app and the url are working together here.
Apologies, that wasn’t very clear. I’ll take a step back …
Have a look at this simple example :
https://anvil.works/ide#clone:N5GEANP7VLC7G6AH=ICAJV63VR7NDWTFRUWMCMCI7
Here I just set up an end point which you can call from a browser. The actual URL is at the bottom of the Server Module window (let me know if you can’t see it), just replace “{path}” with “test”. For example :
https://N5GEANP7VLC7G6AH.anvilapp.net/_/private_api/MQ3NN26R46UZORDRDWFMXQQF/test
(those are my values, yours will be different).
Let’s establish that works first before moving on…
I think the reason you can’t access the endpoint in Nexmo may be due to CORS (cross origin resources being blocked), but you should be able to run it from your own browser.
Oh wow. That is so cool. Clearly I know nothing about the web.
I see how when I paste the url into a browser, it ends up calling a server function. Really neat. In my particular case the server function has parameters. So should I be adding parameters like in the following?:
https://qvzayhl4dfnkmutl.anvilapp.net/_/private_api/V3SJJCIN4RUPDC7DDO3VHC3B/test?param1=5
If I modify your server function so that it takes “param1” as as argument and returns it, this works. The question is how does the url know how to send along the msisdn and text parameters when routed through Nexmo?
I feel that I’m very close here…
Marvellous - progress 
Nexmo is going to be adding the parameters itself. When you send the SMS, it goes into Nexmo then Nexmo looks up your webhook and calls the URL, adding the parameters. I am guessing that Anvil Central have already checked that they are in the correct format for their example.
So, go back to your SMS app now and make sure you have the correct API URL (I suspect the one you posted originally was not correct). Add that into Nexmo and see what happens.
(by the way - ignore my CORS comment above - that’s only relevant if you are returning a response which was true for my test app but not true for the SMS example).
ahh, for some reason I can’t seem to find where I got the Nexmo number I’m texting just to see if I have that correct. However, I do have a twillio account and I can see the number they give me to text.
The confusing thing is that the SMS app that Ian shared shows two urls to use as webhooks and neither of them work for me. The first shows up underneath the server module (where yours did too), and the second shows up in a window when you run the app.
https://iirrkt7nsmnopcv5.anvilapp.net/_/api/sms
https://iirrkt7nsmnopcv5.anvilapp.net/version/dev/18954cc71c18927c//api/sms
Here is a screenshot of the twillio webhook setting.
Can you tell what I am missing here?
For Twilio, try replacing msisdn with “From” and text with “Body” (in your Anvil endpoint).
I just called both of those URLs with msisdn & text added on the end and they seemed to work fine (you should see msisdn 123 and Hello or davetest as the messages in your db). By work fine I mean there were no errors.
Okay, trying now…gimme one sec
Hmm,
Still nothing when I change the server function like so:
def incoming_sms(From, Body, **kw):
Is that what you meant for me to do?
I do not see any entries in the database how did call on the app with those parameters?
Shoot, sorry, I see your messages in the message table (there are two tables). I can also use resttest.com, set the parameters there, and get data sent to the app. Great.
Now, I just need to figure out how to get Twillio to do that…
Ok, can you set your webhook to this URL :
https://n5geanp7vlc7g6ah.anvilapp.net/_/private_api/MQ3NN26R46UZORDRDWFMXQQF/test
and send a test SMS in. I want to see if I can see the parameters.
Do you want the server function to use From and Body, or the original parameters?
This is in the Twilio webhook setting. I want to have the SMS hook call my application here so I can see what Twilio sends.
Right right. Okay, I sent a text saying hello
Perfect 
Ok, I got the message. Right, here’s what you need to do …
Your API end point parameters - remove everything except the “**kwargs”.
Pull out the SMS sender with :
from = kwargs['From']
and the message with :
body = kwargs['Body']
and store those. See if that works.
I must be getting somewhere because I see the bar chart accepting data when sending the request through resttest.com.
Okay, I’ll try that right this minute!