Why is Tradingview Webhook sending empty messages to my API - node.js

how're you feeling today ?
Well I'm here because I've created a trading bot in NodeJs/Express which is receiving alerts from TradingView and then sending trades to Binance. Everything's working fine when I am sending requests with Postman but when I have requests from TradingView the request.body is always empty. Whatever I put in the alert message doesn't appear in the request.
I changed from bodyParser to express.json because I saw bodyParser was depreciated, I also changed the message several times in TradingView without any result. Just one time I tried with a test message : { "message": "test" } and I received it, but that's the only message I was able to get in my req.body
This is the message I'm trying to send :
{
"passphrase": "IJKYJS47",
"exchange": "0BINANCE_TEST",
"ticker": {{ticker}},
"strategy": "TEST_STRATEGY",
"side": "sell",
"order_price": {{close}},
"leverage": "3",
"req_type": "exit",
"order_size": "50",
"stop_loss": "1",
“tp_size”: “0.2”
}
I tried to reduce the message and not to send the variables (ticker and close) but that doesn't change anything to my issue.
Thank you for your help,
Have a great day !

Related

Unable to register for push notifications with Google Classroom API

I'm trying to register to receive push notifications to receive course work for the Classroom API, but I'm running into a brick wall it seems like, as I just can't seem to figure out what to do.
I am using this to register:
const CourseRegistration = classroomAPI.registrations.create();
and by looking at the documentation I thought I would just need to supply this:
{
"feed": {
"feedType": "COURSE_WORK_CHANGES",
"courseWorkChangesInfo": {
"courseId": "courseidhere"
}
},
"cloudPubsubTopic": {
"topicName": "topicnamehere"
}
}
but I always run into this error:
Invalid JSON payload received. Unknown name "feed[courseWorkChangesInfo][courseId]": Cannot bind query parameter. Field 'feed[courseWorkChangesInfo][courseId]' could not be found in request message.
It seems to me that I have tried everything to get it to work with no avail. Any help would be greatly appreciated; I clearly have no idea what I'm doing.

AWS Lex Lambda return multiple lines with Python

I've been reading the AWS Lex / Lambda docs and looking at the examples.
I don't see a way to return multiple lines.
I want to create an intent that when a user types 'Help' It gives me an output like below.
Options:
Deploy new instance.
Undeploy instance.
List instances.
I've tried this:
def lambda_handler(event, context):
logger.debug('event.bot.name={}'.format(event['bot']['name']))
a = {
"dialogAction": {
"type": "Close",
"fulfillmentState": "Fulfilled",
"message": {
"contentType": "PlainText",
"content": "Options: \nDeploy instance.\nUndeploy instance."
}
}
}
return a
How a message is displayed to the user completely depends on the output Channel you are using.
\n works well in Facebook and Slack that I know of.
The Lex Console Test Chat has its own unique formatting for displaying the Lex output, so its not very reliable for testing the formatting of a message. Its really only good for quick tests to make sure your bot responds without errors. And for a glimpse at the Lex JSON response.
Each output Channel will receive the Lex JSON response and display it in its own way, so the only reliable way to test message formatting, links, images, and response cards is to test it in the actual Channel.

How to extract postback data from payload to parameters in Dialogflow V2

I'm stuck in trying to figure this out and I hope someone out there can help me out. I am using the Dialogflow console to create a bot that requests a user to report "something" by providing his/her location and describing the incident. The bot is integrated with Facebook Messenger. One of my intents has a follow up intent which also has a follow up intent like:
intent 1
|
intent 2
| intent 3
Intent 1 requests for the user's location, intent 2 retrieves the user's location and asks the user to describe the location. Intent 3 SHOULD have all the data in context as it's fulfilled by the a webhook. All the data SHOULD be posted to my server. The problem is that I have failed to get the location data (maybe lat and long) I notice that the data comes back in the following format after the fired event FACEBOOK_LOCATION:
{
"originalDetectIntentRequest": {
"source": "facebook",
"payload": {
"postback": {
"data": {
"lat": 14.556761479425,
"long": 121.05444780425
},
"payload": "FACEBOOK_LOCATION"
},
"sender": {
"id": "1588949991188331"
}
}
}
My question is how to I carry that payload data into my Dialogflow Intent Parameters so that they are carried in context until my webhook is fired? I hope i've explained it well. Thanks for the help guys.
You can use the output contexts to save the parameters.
{
"fulfillmentText":"This is a text response",
"fulfillmentMessages":[ ],
"source":"example.com",
"payload":{
"google":{ },
"facebook":{ },
"slack":{ }
},
"outputContexts":[
{
"name":"context name",
"lifespanCount":5,
"parameters":{
"param":"param value"
}
}
],
"followupEventInput":{ }
}
Once you save the parameters, in the subsequent requests, you can access the parameters by accessing saved context. The lifespanCount will decide how many subsequent calls this context is valid. So in the above, eg. parameters saved in intent 1 will be available till intent 5 (if you have 2 more follow up intents)
You can follow more details here.
I personally like to use the client library to develop webhooks as they are easy to use, featureful and reduces JSON manipulation errors. If you like to use NodeJs based client, you can follow this link.
To expand on Abhinav's answer (and point out what caught me up on this issue). You need to make sure that the entities you extracted have the lifespan to make it to your webhook fulfillment call.
You can adjust the count by editing the number and saving.
The lifespanCount will decide how many subsequent calls this context is valid. - Abhinav
If your parameters are not showing up in your output context they probably don't have the appropriate lifespan.

Requests JSON body for inbound voice calls

I can't find any strict information about two requests with are made by Nexmo to "answer" end "event" services. I'm confused.
When I make a call to my virtual number first is my "answer" URL is called. Question is how JSON body of that request looks like? Can you provide me some example of that request to "answer" URL?
Then after welcome speach user make a choise and "event" service is called. As I understand JSON body for that POST request looks like that:
{
"dtmf": "2",
"timed_out": false,
"uuid": "cwa3126675f721esueedc762c9ft94b7",
"conversation_uuid": "CON-w4e9ae1-28ka-1234-ic63-65d022433343",
"timestamp": "2018-01-27T17:59:39.963Z"
}
Am I right?
Best regards,
Radek
The webhook to your answer event contains 4 values:
to: The endpoint being called.
from: The endpoint you are calling from.
conversation_uuid: The unique ID for this Conversation.
uuid: The unique ID for this Call.
By default this request is a GET and those will be query params, you can change the method to POST if you need it in that format and you will get JSON like this:
{
"from": "447700900001",
"to": "447700900002",
"uuid": "CON-9faebf2c-6609-40e2-adaa-95444b6ca352",
"conversation_uuid": "CON-9faebf2c-6609-40e2-adaa-95444b6ca352"
}
The 'Call Progress Events' reference is here, generally there are 2/3 different categories of events:
Call progess which is things like when the call is started answered & completed and then 2 other events which are in response to an input action or a record action.
https://developer.nexmo.com/api/voice#webhook
I must apologize it's currently not as easy as it should be to find this in our docs, but we've just started a rewrite of these pages and hopefully it will be much clearer soon.

Clear "pending_update_count" in Telegram Bot

I want to clear all pending_update_count in my bot!
The output of below command :
https://api.telegram.org/botxxxxxxxxxxxxxxxx/getWebhookInfo
Obviously I replaced the real API token with xxx
is this :
{
"ok":true,"result":
{
"url":"",
"has_custom_certificate":false,
"pending_update_count":5154
}
}
As you can see, I have 5154 unread updates til now!! ( I'm pretty sure this pending updates are errors! Because no one uses this Bot! It's just a test Bot)
By the way, this pending_update_count number are increasing so fast!
Now that I'm writing this post the number increased 51 and reached to 5205 !
I just want to clear this pending updates.
I'm pretty sure this Bot have been stuck in an infinite loop!
Is there any way to get rid of it?
P.S:
I also cleared the webhook url. But nothing changed!
UPDATE:
The output of getWebhookInfo is this :
{
"ok":true,
"result":{
"url":"https://somewhere.com/telegram/webhook",
"has_custom_certificate":false,
"pending_update_count":23,
"last_error_date":1482910173,
"last_error_message":"Wrong response from the webhook: 500 Internal Server Error",
"max_connections":40
}
}
Why I get Wrong response from the webhook: 500 Internal Server Error ?
I think you have two options:
set webhook that do nothing, just say 200 OK to telegram's servers. Telegram wiil send all updates to this url and the queque will be cleared.
disable webhook and after it get updates by using getUpdates method, after it, turn on webhook again
Update:
Problem with webhook on your side. You can try to emulate telegram's POST query on your URL.
It can be something like this:
{"message_id":1,"from":{"id":1,"first_name":"FirstName","last_name":"LastName","username":"username"},"chat":{"id":1,"first_name":"FirstName","last_name":"LastName","username":"username","type":"private"},"date":1460957457,"text":"test message"}
You can send this text as a POST query body with PostMan for example, and after it try to debug your backend.
For anyone looking at this in 2020 and beyond, the Telegram API now supports clearing the pending messages via a drop_pending_updates parameter in both setWebhook and deleteWebhook, as per the API documentation.
Just add return 1; at the end of your hook method.
Update:
Commonly this happens because of queries delay with the database.
I solved is like this
POST tg.api/bottoken/setWebhook to emtpy "url"
POST tg.api/bottoken/getUpdates
POST tg.api/bottoken/getUpdates with "offset" last update_id appeared before
doing this serveral times
POST tg.api/bottoken/getWebhookInfo
had a look if all away.
POST tg.api/bottoken/setWebhook with filled "url"
If you are using webhook, you can follow these steps
On your web browser, enter the following url with your right value of bot
https://api.telegram.org/bot/getWebhookInf
You will get a result like this on your screen
{"ok":true,"result":{"url":"url_value",...}}
On the displayed result, copy the entire url_value without quotes and replace it on this second url
https://api.telegram.org/bot/setWebhook?url=url_value&drop_pending_updates=True
Enter the second url with right bot and url_value in your web browser then press ENTER
Done!
i solve it by Change file access permissions file - set permissions file to 755
and second increase memory limit in php.ini file
A quick&dirty way is to get a temporary webhook here: https://webhook.site/ and
set your webhook to that (it will answer with a HTTP/200 code everytime, reseting your pending messages to zero)
I faced the same issue for my tele bot after user edited existing message. My bot receives update with editedMessage continuously, but update.hasMessage() was empty. As a result number of updates rocketly increased and my bot stack.
I solved this issue by adding handling for use case when message is missing - send 200 code:
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context) {
update = MAPPER.readValue(event.getBody(), Update.class);
if (!update.hasMessage()) {
return new APIGatewayProxyResponseEvent()
.withStatusCode(200) // -> !!!!!! return code 200
.withBody("message is missing")
.withIsBase64Encoded(false);
}
... ... ...

Resources