Skip to content
This repository has been archived by the owner on Oct 1, 2023. It is now read-only.

Action block "elements" must be array #17

Open
nathanheffley opened this issue Sep 27, 2021 · 5 comments
Open

Action block "elements" must be array #17

nathanheffley opened this issue Sep 27, 2021 · 5 comments
Assignees

Comments

@nathanheffley
Copy link
Owner

Im experiencing this issue now and I cant get it to work with your "test"-example:

return (new SlackMessage)
    ->attachment(function ($attachment) {
        $attachment
            ->block(function ($block) {
                $block
                    ->type('actions')
                    ->elements([
                        'type' => 'button',
                        'text' => [
                            'type' => 'plain_text',
                            'text' => 'Cancel',
                        ],
                    ]);
            });
    });

Laravel throws a bad request with invalid_attachments response.

Its working fine with a text section.

I had the original laravel notification package installed prior to yours, but uninstalled before installing yours.
I've tried to clear composer cache, dump auto load and run composer install again.

I still get the error. Any idea on how to get it to work?

EDIT:
Okay, so for some reason I can only get it to work with an extra [] around the elements, compared to the test example:

->elements([
    [
        'type' => 'button',
        'text' => [
            'type' => 'plain_text',
            'text' => 'Approve',
            'emoji' => false,
        ],
        'value' => 'click_me_123',
        'action_id' => 'approve_x',
        'style' => 'primary',
    ]
]);

Originally posted by @ejerskov in #4 (comment)

@nathanheffley
Copy link
Owner Author

Hey @ejerskov I moved your comment to a new issue. I am not sure the best way to improve the interface, although updating the test does seem like a good idea at they very least. The elements does require an array but of course that doesn't ensure that it's an array of a specific object, and I don't want to break backwards compatibility over this since it does have an easy fix. If you have any ideas that would've helped you figure out the solution faster (I'm not sure how long it took you to fix it on your own) but at the very least this issue can stay here so that if anyone has an issue in the future they can see this ticket and find the solution quickly.

@ejerskov
Copy link

Hi @nathanheffley. Make sense! Its just that without much documentation I had to read the tests to see examples so good idea to update those.

@nathanheffley
Copy link
Owner Author

Is there some kind of documentation you'd like to see? I've been thinking of creating a block using the Block Builder tool that generates the JSON for you and then converting that into a code snippet for this package, but haven't had the time to do so.

@ejerskov
Copy link

Hi @nathanheffley
Maybe put a reference from the readme to the test file so that it's easier to find examples.

Im actually also looking into sending views to Slack in order to display modals. Is this something that's possible with this package?

@nathanheffley
Copy link
Owner Author

@ejerskov this package is just for sending Slack messages (so no support for modals) so I doubt it will be useful for what you're looking to do.

@nathanheffley nathanheffley self-assigned this Dec 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants