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

Use variables in Command on Message Receipt #81

Open
timfanda35 opened this issue Oct 2, 2022 · 2 comments
Open

Use variables in Command on Message Receipt #81

timfanda35 opened this issue Oct 2, 2022 · 2 comments

Comments

@timfanda35
Copy link
Contributor

I'm confused about the variables $sender and $receiver in Command on Message Receipt .

Would the $sender be Partner AS2 Identifier, and the $receiver be Organization AS2 Identifier?

My test

  • Organization AS2 Identifier: supplier
  • Partner AS2 Identifier: tradingpartner

Advanced Settings - Command on Message Receipt

echo "$receiver got a message from $sender"

When I send the message from tradingpartner to supplier, I expect the log would be

supplier got a message from tradingpartner

but I got:

tradingpartner got a message from supplier

Code Trace

The variables are defined at /pyas2/utils.py:

def run_post_receive(message, full_filename):
    """Execute command after successful receive, can be used to call the
    edi program for further processing"""

    command = message.partner.cmd_receive
    if command:
        logger.debug(f"Execute post successful receive command {command}")

        # Create command template and replace variables in the command
        command = Template(command)
        variables = {
            "filename": os.path.basename(full_filename),
            "fullfilename": full_filename,
            "sender": message.organization.as2_name,
            "receiver": message.partner.as2_name,
            "messageid": message.message_id,
        }
        variables.update(message.as2message.headers)

        # Execute the command
        os.system(command.safe_substitute(variables))

To swap sender and receiver values would more fit the meaning.

        command = Template(command)
        variables = {
            "filename": os.path.basename(full_filename),
            "fullfilename": full_filename,
            "sender": message.partner.as2_name,
            "receiver": message.organization.as2_name,
            "messageid": message.message_id,
        }
@abhishek-ram
Copy link
Owner

Makes sense, can you open a PR with this change?

@timfanda35
Copy link
Contributor Author

Sure.

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

2 participants