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

Add list handling in the send_custom_json method on facebook.py #7247

Closed

Conversation

silvasara
Copy link
Contributor

@silvasara silvasara commented Nov 11, 2020

Proposed changes:

Status (please check what you already did):

  • added some tests for the functionality
  • updated the documentation
  • updated the changelog (please check changelog for instructions)
  • reformat files using black (please check Readme for instructions)

@sara-tagger
Copy link
Collaborator

Thanks for submitting a pull request 🚀 @wochinge will take a look at it as soon as possible ✨

Copy link
Contributor

@wochinge wochinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @silvasara

Thanks for your contribution!
Can you please add tests for this?

@silvasara
Copy link
Contributor Author

@wochinge I don't know if I can do the tests, but I'll try. Where would I put this test? The only test I found for this file was this:

def test_facebook_channel():
# START DOC INCLUDE
from rasa.core.channels.facebook import FacebookInput
input_channel = FacebookInput(
fb_verify="YOUR_FB_VERIFY",
# you need tell facebook this token, to confirm your URL
fb_secret="YOUR_FB_SECRET", # your app secret
fb_access_token="YOUR_FB_PAGE_ACCESS_TOKEN"
# token for the page you subscribed to
)
s = rasa.core.run.configure_app([input_channel], port=5004)
# END DOC INCLUDE
# the above marker marks the end of the code snipped included
# in the docs
routes_list = utils.list_routes(s)
assert routes_list["fb_webhook.health"].startswith("/webhooks/facebook")
assert routes_list["fb_webhook.webhook"].startswith("/webhooks/facebook/webhook")

@wochinge
Copy link
Contributor

@silvasara Yep, it would go into test_channels. You can also create a new file test_facebook.py in tests.core.channels and move all facebook tests there

Base automatically changed from master to main January 22, 2021 11:15
@CLAassistant
Copy link

CLAassistant commented Feb 22, 2021

CLA assistant check
All committers have signed the CLA.

@jppgomes
Copy link
Contributor

Hello, I checked the missing tests for the correction, can I implement and send the pr? @wochinge

@wochinge
Copy link
Contributor

wochinge commented Mar 1, 2021

@jppgomes Sure! It would be a pleasure!

@@ -1,10 +1,10 @@
repos:
- repo: https://github.com/ambv/black
rev: 19.10b0
rev: 20.8b1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please change the items in this file back? These hooks should work as they are once you do poetry install in the cloned repository

assert routes_list["fb_webhook.webhook"].startswith("/webhooks/facebook/webhook")


def test_facebook_send_custon_json_list():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't test send_custom_json - we need to call the actual code in this test (same in the one below)


recipient_id = json_message.pop("sender", {}).pop("id", None) or recipient_id
if isinstance(json_message, list):
if isinstance(json_message.pop(), list):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pop gets and removes stuff from the list - do we really want that?

wavymazy added a commit to wavymazy/rasa that referenced this pull request Mar 21, 2021
@wavymazy
Copy link

wavymazy commented Mar 21, 2021

Hi guys, I'm the author of the post for this issue. I had some time today so I though might as well update this PR.

Context:

I have retested the issue with Facebook to understand where it comes from.
The issue stems from the custom template/response if you have any. Basically, if we follow the template (https://rasa.com/docs/rasa/responses/#custom-output-payloads), it is said that we can send any arbitrary output we want. But what will end up happening if we have 2 "type" items (under "blocks"), is that the output will be a list (under "blocks"). The MessengerBot.send_custom_json() previously didn't handle this well at all.

Example of a custom Json that would cause issues:

{
        "blocks": [
            {"type": "title", "text": {"text": "Conversation progress"}},
            {
                "type": "progression_bar",
                "text": {"text": "progression 1", "level": "1"},
            },
        ]
    }

Propose solution:

I think the best way to handle this is by only looking for the sender ID in the custom template only if that template is of type Dict. Otherwise we could use the ID that is given as a function paramter.

wavymazy added a commit to wavymazy/rasa that referenced this pull request Mar 21, 2021
@wochinge
Copy link
Contributor

that would be awesome if you could wrap this up @wavymazy .

Otherwise we could use the ID that is given as a function paramter.

Would do you mean by this?

@wavymazy
Copy link

Hi @wochinge,

Unfortunately it seems I can't make a direct change to this PR unless given access.

With regards to your question, the ID I'm refering to is the recipient_id that is given as a paramter.

async def send_custom_json( self, recipient_id: Text, json_message: Dict[Text, Any], **kwargs: Any ) -> None:

@wochinge
Copy link
Contributor

@wavymazy How about forking the fork / cherry-picking the commits and then you create a new PR?

@wavymazy
Copy link

Ok @wochinge. I can try this.

@wavymazy wavymazy mentioned this pull request Mar 29, 2021
3 tasks
@wavymazy
Copy link

wavymazy commented Apr 2, 2021

Hi, @wochinge, I created my PR, cherry picking from this one (link : #8332).

@wochinge
Copy link
Contributor

wochinge commented Apr 6, 2021

Awesome! I'll close this one then.

@wochinge wochinge closed this Apr 6, 2021
@ErickGiffoni ErickGiffoni deleted the treat-list-custom-json-facebook branch August 5, 2021 19:42
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.

Type error in facebook.py
6 participants