Yoctol / react-messenger-send-to-messenger

React component for messenger send to messenger plugin
MIT License
17 stars 4 forks source link

Support for Subscribe to Events #5

Open gijo-varghese opened 6 years ago

gijo-varghese commented 6 years ago

FB SDK a provides a way to subscribe to the events of STM button (https://developers.facebook.com/docs/messenger-platform/discovery/send-to-messenger-plugin/#event). Is it possible?

FB.Event.subscribe('send_to_messenger', function(e) {
    // callback for events triggered by the plugin

});
tw0517tw commented 6 years ago

As this component loads the FB sdk for you, I guess you can just use the FB global object to do so. Maybe you can try it on our example.

gijo-varghese commented 6 years ago

@tw0517tw How can I know whether FB is properly bind in window? This is what I've tried:

import PropTypes from "prop-types";
import React from "react";
import MessengerSendToMessenger from "react-messenger-send-to-messenger";

const StmBox = props => (
  <div>
    <MessengerSendToMessenger
      appId="123"
      ctaText={props.ctaText}
      pageId={props.pageId}
      size="xlarge"
    />
  </div>
);

FB.Event.subscribe("send_to_messenger", e => {
  console.log(e);
});

StmBox.propTypes = {
  pageId: PropTypes.string.isRequired,
  ctaText: PropTypes.string,
};

StmBox.defaultProps = {
  ctaText: "SUBSCRIBE_IN_MESSENGER"
};

export default StmBox;

However I'm getting the error: FB is not defined

gijo-varghese commented 6 years ago

@tw0517tw I've created a pull request for this feature. Can you please check it https://github.com/Yoctol/react-messenger-send-to-messenger/pull/6

ChuZhiShen commented 3 years ago

Is the subscribe event solved?