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

[FEAT] Object Payload sent in action #54

Merged
merged 1 commit into from
Aug 29, 2022
Merged

[FEAT] Object Payload sent in action #54

merged 1 commit into from
Aug 29, 2022

Conversation

gaetan1903
Copy link
Member

@gaetan1903 gaetan1903 commented Aug 29, 2022

  • set_action can receive Payload Object
  • action decorator can receive data send in payload object
  • Unit test for Payload in action added

Example

@ampalibe.command("/try_second_action")
def try_second_action(sender_id, **extends):
    query.set_action(
        sender_id, Payload("/second_action_work", myname="Ampalibe", version=2)
    )


@ampalibe.action("/second_action_work")
def second_action_work(sender_id, cmd, myname, version, **extends):
    query.set_action(sender_id, None)
    return cmd + " " + myname + str(version)

TEST

function simulate {
    echo $(curl -H "Content-Type: application/json" -X POST "http://127.0.0.1:4555/?testmode=1" -d "{\"object\": \"page\", \"entry\": [{\"messaging\": [ {\"sender\": {\"id\": \"test_user\"}, \"message\": {\"text\":$1} }]}]}")
}

####### ACTION TEST && Payload data TEST #######
simulate '"/try_second_action"' > /dev/null
res=$(simulate '"Hello"')
if [ "$res" = '"Hello Ampalibe2"' ]; then
    echo "Message: OK Second Action"
    echo "Message: OK Payload data in action"
else
    echo KO
    exit 1
fi

- set_action can receive Payload Object
- action decorator can receive data send in payload object
- Unit test for Payload in action added
@gaetan1903
Copy link
Member Author

gaetan1903 commented Aug 29, 2022

An alternative using temporary data

Using Temporary Data

@ampalibe.command("/try_action")
def try_action(sender_id, **extends):
    query.set_action(sender_id, "/action_work")
    query.set_temp(sender_id, "myname", "Ampalibe")
    query.set_temp(sender_id, "version", "2")


@ampalibe.action("/action_work")
def action_work(sender_id, cmd, **extends):
    query.set_action(sender_id, None)
    myname = query.get_temp(sender_id, "myname")
    version = query.get_temp(sender_id, "version")
    return cmd + " " + myname + version 

Using payload

@ampalibe.command("/try_action")
def try_action(sender_id, **extends):
    query.set_action(sender_id, Payload("/action_work", myname="Ampalibe", version="2"))


@ampalibe.action("/action_work")
def action_work(sender_id, cmd, myname,  version, **extends):
    query.set_action(sender_id, None)
    return cmd + " " + myname + version 

@gaetan1903 gaetan1903 merged commit 6d4bb1c into main Aug 29, 2022
@gaetan1903 gaetan1903 deleted the experiment_action branch August 29, 2022 09:03
@gaetan1903 gaetan1903 restored the experiment_action branch September 1, 2022 17:54
@gaetan1903 gaetan1903 deleted the experiment_action branch September 1, 2022 17:55
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

Successfully merging this pull request may close these issues.

2 participants