Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback when message has been received #51

Open
ioFilippo opened this issue Aug 21, 2020 · 6 comments
Open

Callback when message has been received #51

ioFilippo opened this issue Aug 21, 2020 · 6 comments

Comments

@ioFilippo
Copy link

ioFilippo commented Aug 21, 2020

Hi,
There is a more elegant way to trigger a received message event without monkey patching 'run_post_receive' like I did below?

from pyas2 import utils
import requests


old_run_post_receive = utils.run_post_receive


def new_run_post_receive(message, full_filename):
    old_run_post_receive(message, full_filename)
    payload = dict(
        id='1',
        access_token='xyz'
    )
    r = requests.post('http://127.0.0.1/url/to/post', data=payload)


utils.run_post_receive = new_run_post_receive
@abhishek-ram
Copy link
Owner

abhishek-ram commented Aug 22, 2020

Why not just define this logic in the post receive command?
Create a post receive script post_as2_message_receive.py which would be something like

#!/usr/bin/env python3
import requests

payload = dict(
        id='1',
        access_token='xyz'
)
r = requests.post('http://127.0.0.1/url/to/post', data=payload)

# Put additional post receive logic here

And set Command on Message Receipt: on the partner to path_to_script/post_as2_message_receive.py

@ioFilippo
Copy link
Author

Thanks for your answer.
Good idea but I am not a fan on using external scripts.
Anyway I guess a "Command on Message Receipt" can handle received data too (passing that as a parameter).
Do you have other approaches I could dig into?
What do you think implementing a feature to handle callbacks on such events? (I might work on that)

@abhishek-ram
Copy link
Owner

It would be part of your repo so I don't see it as an external script. I dont see a reason to implement callbacks as it can be handled in this command.

@gainskills
Copy link

I have the same question here.
For my opinion: I prefer to use callback instead of external command.

@ioFilippo
Copy link
Author

I guess with callbacks you can have some pros, for example a return code to refuse the message or the chance to handle the content of the message directly or change headers data too before saving.

@gainskills
Copy link

gainskills commented Sep 2, 2020

Hi @abhishek-ram , @bluebytech ,
I tried an implementation for this and did a pull request: #53.

Could you please review it and share your suggestions?

with the PR, the integration can be done in another Django apps in this way instead of defining an external command

from pyas2.utils import pyas2Utils


def cutmize_run(*args, **kwargs):
    print(args, kwargs)


pyas2Utils.cust_run_post_receive = cutmize_run

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants