I was trying setup AWS Lambda as a webhook for my messenger bot. I use Python 3.6 to build the handler.
Everything was ok if webhook returns 3 to 4 messenges.
When the webhook sends to messenger bot more than 10 messages, this created infinite loop. I have to unsubscribe the bot to make it stop.
One more thing, I built another flask server and use ngrok to test it, everything was ok. There aren't infinite loop no matter how many messages were created
How do I stop it ? I suspect the problem came from AWS Lambda. Thanks!
Check your subscribed events, and make sure you're handling all of them right.
It may be that your code is treating messeging_delivery or messaging _echo like real user messages
I already found the problem. The loop happens because the delay time of Lambda. It took too long to process the request, so during this time, facebook messenger continue to POST request to webhook server
Related
Has anyone ever seen a Lambda function stop randomly?
I've got a method that subscribes to an SNS topic that is published to every hour. I recently had 4 messages come through to the subscriber Lambda and 3 of the four worked perfectly.
CloudWatch gives me all of the console logs I have logged, I get responses from all of the APIs the method reaches out to, end with a success message, but the fourth message logs the console log to CloudWatch and then I get the "Request End" log immediately following. None of the following: console.logs, no error from lambda, no insight as to why it would have stopped, no timeout error, it just stopped.
I've never seen this kind of behavior before and have yet to have a Lambda function stop working without logging out the error (everything that runs is written in a try/catch that has reliably logged the errors until now).
Has anyone ever come across this and have any insight as to what it may be?
I've been working on a Dialogflow chatbot that calls a webhook which can often take more than the 5s delay to process and answer the user's request. So, following this post, my webhook sends a response containing a followup event if the processing is too long, and will be able to answer the following request sent by the intent triggered by the event.
Now, while this approach is working great, I have two questions :
Is there any way to send a message ("Please wait, I'm processing your request") to the user on every followup event ?
Since I'm using the Dialogflow-Messenger integration, is there any way to display the three dots "typing" animation while the webhook is processing the request ?
Thanks !
When developing a chatbot, you should keep in mind that you are trying to duplicate how 2 humans interact. You are developing a conversation and in the conversation, we should not keep other person waiting. All your requests should be completed within 4-5 seconds (to avoid timeout by the platform) to have a better UX.
So there is no way to show either Please Wait or animated 3 dots!
Write a good backend code to fetch response faster or tweak and cache your response. Dialogflow is currently designed for 1-1 conversation and cannot provide multiple delayed responses. If you need it that way, you will require to develop your own NLP engine.
I have an app we have connected to Pubnub for a live socket service to keep data on the page fresh for the user.
I have an ajax call that will do something with our API, and when it is successful I call an action on the application controller. At or around the same time, as long as Pubnub is still connected it receives a message with the action handler name and it attempts to call the same action.
Ideally I want to make sure this code only runs once weather it was first called by Pubnub or by my ajax success callback. How can I do this maybe using the ember run loop? It seems viable here I'm just not able to wrap my head around how I would actually do this.
Well, I would only use the web socket.
But for your question:
There is not build-in functionality in the runloop to do that. You will need some kind of uniq message id, and then have a list of processed messages and check there before you run your code.
I have now succesfully setup Django-celery to check after my existing tasks to remind the user by email when the task is due:
#periodic_task(run_every=datetime.timedelta(minutes=1))
def check_for_tasks():
tasks = mdls.Task.objects.all()
now = datetime.datetime.utcnow().replace(tzinfo=utc,second=00, microsecond=00)
for task in tasks:
if task.reminder_date_time == now:
sendmail(...)
So far so good, however what if I wanted to also display a popup to the user as a reminder?
Twitter bootstrap allows creating popups and displaying them from javascript:
$(this).modal('show');
The problem is though, how can a celery worker daemon run this javascript on the user's browser? Maybe I am going a complete wrong way and this is not possible at all. Therefore the question remains can a cronjob on celery ever be used to achieve a ui notification on the browser?
Well, you can't use the Django messages framework, because the task has no way to access the user's request, and you can't pass request objects to the workers neither, because they're unpickable.
But you could definitely use something like django-notifications. You could create notifications in your task and attach them to the user in question. Then, you could retrieve those messages from your view and handle them in your templates to your liking. The user would see the notification on their next request (or you could use AJAX polling for real-time-ish notifications or HTML5 websockets for real real-time [see django-websocket]).
Yes it is possible but it is not easy. Ways to do/emulate server to client communication:
polling
The most trivial approach would be polling the server from javascript. Your celery task could create rows in your database that can be fetched by a url like /updates which checks for new updates, marks the rows as read and returns them.
long polling
Often referred to as comet. The client does a request to the server which pends until the server decides to return something. See django-comet for example.
websocket
To enable true server to client communication you need an open connection from the client to the server. django-socketio and django-websocket are examples of reusable apps that make this possible.
My advice judging by your question's context: either do some basic polling or stick with the emails.
I have a service broker message queue, each message calls a web service via a CLR stored procedure to do some processing
I have an issue where the conversation does not end, it works fine, everything it needs to do is done, it doesn't error, but the conversation never ends even though EndConversation is called.
It seems to be coming back from the web service call and calling EndConversation before the processing that the web service is doing has completed, and so the conversation does not end and the message is called again.
Is there anyway to stop the web service call coming back before it has completed so then the conversation in the message queue can end successfully.
I believe this is what is happening because if i cut out some of the work the web service call is doing so that it runs quicker than everything runs fine and the conversation ends.
I have also stepped through all of the steps happening in the web service call, and everything works, there are no errors etc.
May need to see some of the code, especially the initiator.
Are you using explicit transactions?
Make sure you have a COMMIT TRANSACTION statement after END CONVERSATION.