Giter VIP home page Giter VIP logo

Comments (15)

jason-engage avatar jason-engage commented on June 18, 2024 2

It appears that null value should be used explicitly as the proper workaround (reason why I am not seeing any issue). If we update the code we need to use @wolzogen cleaner version, so the pull request should be resubmitted with the cleaner/shorter code.

from fb-messenger-php.

jason-engage avatar jason-engage commented on June 18, 2024

from fb-messenger-php.

pulkit8 avatar pulkit8 commented on June 18, 2024

Thanks Jason for replying even on Sunday.

Yes, I cloned the latest code with the folders Menu and Messages along with FbBotApp.php file and update the same in mine.
Was their any particular update sent for Structured message of generic message type ? If so, please it would be great if you can link me to the commit so that I can cross check.

from fb-messenger-php.

pulkit8 avatar pulkit8 commented on June 18, 2024

Just tried the following code too, this also fails to work.

  case 'generic':
                    $bot->send(new StructuredMessage($message['sender']['id'],
                        StructuredMessage::TYPE_GENERIC,
                        [
                            'elements' => [
                                new MessageElement("First item", "Item description", "", [
                                    new MessageButton(MessageButton::TYPE_POSTBACK, 'First button'),
                                    new MessageButton(MessageButton::TYPE_WEB, 'Web link', 'http://facebook.com')
                                ]),
                                new MessageElement("Second item", "Item description", "", [
                                    new MessageButton(MessageButton::TYPE_POSTBACK, 'First button'),
                                    new MessageButton(MessageButton::TYPE_POSTBACK, 'Second button')
                                ]),
                                new MessageElement("Third item", "Item description", "", [
                                    new MessageButton(MessageButton::TYPE_POSTBACK, 'First button'),
                                    new MessageButton(MessageButton::TYPE_POSTBACK, 'Second button')
                                ])
                            ]
                        ],
                        [ 
                        	new QuickReplyButton(QuickReplyButton::TYPE_TEXT, 'QR button','PAYLOAD')
                        ]
                    ));
                    break;

P.S : Other functionality are working, hence I am figuring out some code issue with particular 'generic' message type.
Curl error and json_encode were the major update done recently I believe only the FbBotApp.php.

from fb-messenger-php.

jason-engage avatar jason-engage commented on June 18, 2024

from fb-messenger-php.

pulkit8 avatar pulkit8 commented on June 18, 2024

Yes, it was working well before and then it got stopped working all of a sudden.
Basically when the http_build_query issue arose 2 days ago, I tried debugging and fixed the same by using json_encode which then I realised the same has been fixed here, which made be update my pimax lib for any other open issues too.

Since then the Generic template has stopped working and I haven't been able to find any temporary fix too.

Meanwhile tried a core php generic template php code too, it also failed to work.
I am bit confused, how come only Generic template not working.

Sample core php code I tried :

         case 'test':
                       
     $answer = ["attachment"=>[
      "type"=>"template",
      "payload"=>[
        "template_type"=>"generic",
        "elements"=>[
          [
            "title"=>"Welcome to fb bot",
            "item_url"=>"https://www.basezap.com/guide-to-flush-redis-databases-and-keys/",
            "image_url"=>"https://www.basezap.com/wp-content/themes/basezap/images/logo.png",
            "subtitle"=>"We\'ve got the right hat for everyone.",
            "buttons"=>[
              [
                "type"=>"web_url",
                "url"=>"https://google.com",
                "title"=>"View Website"
              ],
              [
                "type"=>"postback",
                "title"=>"Start Chatting",
                "payload"=>"DEVELOPER_DEFINED_PAYLOAD"
              ]              
            ]
          ]
        ]
      ]
    ]];
                            $senderID = $message['sender']['id'];
     $response = [
    'recipient' => [ 'id' =>$senderID  ],
    'message' => $answer 
];


$ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.Yii::app()->params['token']);    // You need to update your token variable here.
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
if(!empty($input)){
$result = curl_exec($ch);
}
curl_close($ch);

break;

Can you please try above code, if it works for you ?

from fb-messenger-php.

o2-web avatar o2-web commented on June 18, 2024

@pulkit8 what does the $result variable contain?

PS: this piece of code works fine for me

from fb-messenger-php.

pulkit8 avatar pulkit8 commented on June 18, 2024

The above code works, I forgot to correct this

 
if(!empty($input)){
$result = curl_exec($ch);
}

to
$result = curl_exec($ch);

So, now the issue is only with the the library structured message of type Generic and List

Here is the error

{"error":{"message":"(#100) The parameter name_placeholder[elements][0][default_action][type] is required","type":"OAuthException","code":100,"fbtrace_id":"CI6GGsRsdTy"}}

I have submitted pull request for the fix.

Basically the MessageElement needs a check for non empty default action parameter. From now, facebook doesn't allow the particular parameter to be blank for structured message of type list and generic.

Thank you everyone for the support.

from fb-messenger-php.

jason-engage avatar jason-engage commented on June 18, 2024

from fb-messenger-php.

pulkit8 avatar pulkit8 commented on June 18, 2024

The code needs a fix to support generic and list type of structured message. It fails in absence of call action.

from fb-messenger-php.

jason-engage avatar jason-engage commented on June 18, 2024

from fb-messenger-php.

wittfabian avatar wittfabian commented on June 18, 2024

#149

from fb-messenger-php.

yourchoice avatar yourchoice commented on June 18, 2024

HI,

I have same error too

image

And

[error] => Array
        (
            [message] => (#100) The parameter name_placeholder[elements][0][default_action][type] is required
            [type] => OAuthException
            [code] => 100
            [fbtrace_id] => CzjZId6Micu
        )

)

from fb-messenger-php.

yourchoice avatar yourchoice commented on June 18, 2024

FInally, Ifound a way for this sequence:

$rsp = $bot->send(new StructuredMessage($senderid, StructuredMessage::TYPE_GENERIC, [
        'elements' => [
            new MessageElement($user->getFirstName().' '.$user->getLastName(), ' ', $user->getPicture())
        ]
    ],
    [
       new QuickReplyButton(QuickReplyButton::TYPE_TEXT, 'QR button','PAYLOAD')
    ]
));

Problem is here:
new MessageElement($user->getFirstName().' '.$user->getLastName(), ' ', $user->getPicture())

construct of it is:
__construct($title, $subtitle, $image_url = '', $buttons = [], $url = '', $default_action = [])

Seems that better is to init default for $default_action = null...

To work, just i add on call null parameter:
new MessageElement($user->getFirstName().' '.$user->getLastName(), ' ', $user->getPicture(), null, null, null)

from fb-messenger-php.

pulkit8 avatar pulkit8 commented on June 18, 2024

Yes definitely the cleaner code should be updated. Have created a new pull request with the same.

Applying the patch would surely solve the problem for people referring the example code for development.

from fb-messenger-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.