{"id":411060,"date":"2024-10-15T08:00:00","date_gmt":"2024-10-15T08:00:00","guid":{"rendered":"https:\/\/www.weixiaoduo.com\/plugins\/all-path-messaging\/"},"modified":"2024-10-17T15:06:00","modified_gmt":"2024-10-17T15:06:00","slug":"all-path-messaging","status":"publish","type":"post","link":"https:\/\/www.weixiaoduo.com\/plugins\/all-path-messaging\/","title":{"rendered":"All Path Messaging"},"content":{"rendered":"<p><a href=\"https:\/\/github.com\/Souptik2001\/all-path-messaging\" rel=\"nofollow ugc\">Check out the Github Repository \u2665<\/a><\/p>\n<p><strong>Limitless Communication:<\/strong> All-in-one, super scalable, messaging Solution for WordPress.<\/p>\n<p>Ok hold on! \u270b. So, many words in one line.<br \/>\nLet\u2019s understand each one-by-one.<\/p>\n<ul>\n<li><strong>All-in-one:<\/strong> What do you want? \u2013 Email, SMS, push-notification? Get all-in-one.\n<ul>\n<li>But I don\u2019t want to use <code>xyz<\/code> provider for SMS, I want to use <code>pqr<\/code>, can I have that? Yes it provides you with lot of pre implemented providers for all email, sms and push-notification.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Super Scalable:<\/strong> But I want to use an email provider named <code>yxr<\/code> you haven\u2019t heard the name of. Now what? \ud83e\uddd0\n<ul>\n<li>No worries! Are you a developer? If yes, just write your own plugin and implement your own adapter and see it nicely hooked-up with \u201cWordPress messaging\u201d. Please refer to <a href=\"https:\/\/github.com\/Souptik2001\/wp-messaging\/wiki\/Create-your-own-Adapter-%F0%9F%9B%A0%EF%B8%8F\" rel=\"nofollow ugc\">this<\/a> section for implementing adapters.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>And that\u2019s how it provides <strong>Limitless communication<\/strong>! \ud83d\ude80<\/p>\n<h3>Quick Links<\/h3>\n<p><a href=\"https:\/\/github.com\/Souptik2001\/wp-messaging\/wiki\/Setup-%E2%9A%99%EF%B8%8F\" rel=\"nofollow ugc\">Setup \u2699\ufe0f<\/a> | <a href=\"https:\/\/github.com\/Souptik2001\/wp-messaging\/issues\" rel=\"nofollow ugc\">Issues<\/a> | <a href=\"https:\/\/github.com\/Souptik2001\/wp-messaging\/wiki\/Services-and-functions-%F0%9F%A7%A9\" rel=\"nofollow ugc\">Services and functions \ud83e\udde9<\/a> | <a href=\"https:\/\/github.com\/Souptik2001\/wp-messaging\/wiki\/Create-your-own-Adapter-%F0%9F%9B%A0%EF%B8%8F\" rel=\"nofollow ugc\">Create your own Adapter \ud83d\udee0\ufe0f<\/a><\/p>\n<h3>Coming soon \u23f3<\/h3>\n<ul>\n<li>Push notifications<\/li>\n<li>Email Testing page<\/li>\n<li>SMS Testing page<\/li>\n<li>Push notifications Testing page<\/li>\n<\/ul>\n<h3>Examples<\/h3>\n<h4>Email \ud83d\udce7\ud83d\udce8<\/h4>\n<p>Send an email through a particular adapter (with headers \ud83d\ude09) \u2013<\/p>\n<pre><code>SouptikAllPathMessagingEmailsend(\n  [ 'dev2@souptik.dev' ],\n  'Yay its working!',\n  'This is some long mail body.',\n  'Souptik',\n  'dev1@souptik.dev',\n  [\n   'cc' => [\n    [\n     'name'  => 'CC Test',\n     'email' => 'cc@souptik.dev',\n    ],\n   ],\n   'attachments' => [\n    trailingslashit( WP_CONTENT_DIR ) . '\/mu-plugins\/test-all-path-messaging.php',\n     'SameFileDifferentName.php' => trailingslashit( WP_CONTENT_DIR ) . '\/mu-plugins\/test-all-path-messaging.php',\n   ],\n  ],\n  'mailgun'\n );\n<\/code><\/pre>\n<p>Just remove the last parameter! And now it uses the default selected adapter \u2013<\/p>\n<pre><code>SouptikAllPathMessagingEmailsend(\n  [ 'dev2@souptik.dev' ],\n  'Yay its working!',\n  'This is some long mail body.',\n  'Souptik',\n  'dev1@souptik.dev',\n  [\n   'cc' => [\n    [\n     'name'  => 'CC Test',\n     'email' => 'cc@souptik.dev',\n    ],\n   ],\n   'attachments' => [\n    trailingslashit( WP_CONTENT_DIR ) . '\/mu-plugins\/test-all-path-messaging.php',\n     'SameFileDifferentName.php' => trailingslashit( WP_CONTENT_DIR ) . '\/mu-plugins\/test-all-path-messaging.php',\n   ],\n  ],\n );\n<\/code><\/pre>\n<p>Checked the override <code>wp_mail<\/code> checkbox? Try a simple <code>wp_mail<\/code>! \u2013<\/p>\n<pre><code>wp_mail(\n  [ 'dev2@souptik.dev' ],\n  'Yay its working!',\n  'This is some long mail body - from <strong>wp_mail<\/strong>.',\n  [],\n  []\n );\n<\/code><\/pre>\n<h4>SMS \ud83d\udcf2<\/h4>\n<p>Send a SMS through a particular adapter \u2013<\/p>\n<pre><code>SouptikAllPathMessagingSMSsend( [ '+xxxxxxxxxxxx' ], 'Yay its working!', 'twilio' );\n<\/code><\/pre>\n<p>Just remove the last parameter! And now it uses the default selected adapter \u2013<\/p>\n<pre><code>SouptikAllPathMessagingSMSsend( [ '+xxxxxxxxxxxx' ], 'Yay its working!' );\n<\/code><\/pre>\n<h3>Creating your own adapter \ud83d\udee0\ufe0f<\/h3>\n<p>Here comes the cool part fellow developers! \ud83d\udcbb<\/p>\n<p><strong>Tip:<\/strong> I have provided a dummy adapter for each service at <code>inc\/<service>\/adapters\/dummy\/<\/code>.<\/p>\n<p>Consider that as the starting point and let\u2019s understand what each file does.<\/p>\n<ul>\n<li>Let\u2019s start with <code>namespace.php<\/code>. It is the entry point of your adapter.\n<ul>\n<li>In that you will see a simple <code>bootstrap<\/code> function.<\/li>\n<li>In that function we are hooking into <code>EMAIL_SLUG . '_adapters'<\/code> and registering our adapter.<\/li>\n<li>We pass the following data \u2013<\/li>\n<li><code>slug<\/code><\/li>\n<li><code>name<\/code><\/li>\n<li><code>adapter<\/code> class object.<\/li>\n<li><code>options<\/code> \u2013 An array defining the settings required for this adapter, which will be used to automatically display the options on the settings page.<\/li>\n<\/ul>\n<\/li>\n<li>Next is <code>class-adapter.php<\/code>, which is the Adapter class, which we initialized in the above file and passed it to <code>adapter<\/code>. It contains three simple functions \u2013\n<ul>\n<li><code>get_settings_fields<\/code> \u2013 This is the function which returns the array of options, which we used in the above file for <code>options<\/code>. Each option, will have \u2013<\/li>\n<li>The key as the name of the option.<\/li>\n<li>And three values \u2013\n<ul>\n<li><code>label<\/code> \u2013 Label to display in the settings page beside the input.<\/li>\n<li><code>type<\/code> \u2013 Type of the field.<\/li>\n<li><code>sanitize_callback<\/code><\/li>\n<\/ul>\n<\/li>\n<li><code>get_settings<\/code> \u2013 This function returns an associative array, whose keys are the name of the options and the value as the value of the options.<\/li>\n<li><code>get_adapter<\/code> \u2013 This function will just return the core provider class, which is responsible for processing the message.<\/li>\n<li>First check if <code>Utopia Messaging<\/code> already provides the provider or not <a href=\"https:\/\/github.com\/utopia-php\/messaging?tab=readme-ov-file#adapters\" rel=\"nofollow ugc\">here<\/a>, for example <code>UtopiaMessagingAdapterEmailMailgun<\/code>.<\/li>\n<li>If it is present just use it. Easy peasy! \u2728<\/li>\n<li>But if not, let\u2019s code it ourself, because <code>Utopia Messaging<\/code> makes it so easy to create a new adapter!<\/li>\n<\/ul>\n<\/li>\n<li><code>class-dummy.php<\/code> is for that purpose, assuming you don\u2019t get a provider already present in <code>Utopia Messaging<\/code>.\n<ul>\n<li>It\u2019s basically a child class of <code>EmailAdapter<\/code> or <code>SMSAdapter<\/code>, which abstract a lot of stuff for us!<\/li>\n<li>Let me explain two main functions, <code>_construct<\/code> and <code>process<\/code>. <em>Rest of the functions and properties are self-explanatory!<\/em> \ud83d\ude09<\/li>\n<li>In the <code>_construct<\/code> function just put the arguments which you want to accept. That\u2019s it! And now they will be available everywhere else as <code>$this->param_name<\/code>!<\/li>\n<li>The <code>process<\/code> function is the place where you have to write the main logic of calling your providers API to send the message.\n<ul>\n<li>As said above all the credentials\/data you accepted through constructor are available as <code>$this->param_name<\/code>.<\/li>\n<li>Build the <code>body<\/code> and the <code>headers<\/code>.<\/li>\n<li>And then you can use the <code>$this->request<\/code> function as demonstrated in the dummy!<\/li>\n<li>Create a response using Utopia\u2019s <code>Response<\/code> class.<\/li>\n<li>Handle the errors, populate the response, return! Done! \ud83d\ude80<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>External services<\/h3>\n<h4>Brevo<\/h4>\n<p>This plugin connect\u2019s to Brevo\u2019s API to send emails through Brevo. This is the <a href=\"https:\/\/api.brevo.com\/v3\/smtp\/email\" rel=\"nofollow ugc\">API<\/a> it sends the request to.<br \/>\nThe request is send everytime a mail is sent, and Brevo is selected as the default adapter from the plugin settings (or the function to send email through Brevo is directly invoked in the code).<br \/>\nHere is the <a href=\"https:\/\/www.brevo.com\/legal\/termsofuse\/\" rel=\"nofollow ugc\">Terms of Use<\/a> and <a href=\"https:\/\/www.brevo.com\/legal\/privacypolicy\/\" rel=\"nofollow ugc\">Privacy Policy<\/a> of the service.<\/p>\n<h4>AWS SES<\/h4>\n<p>This plugin connect\u2019s to AWS SES\u2019s API to send emails through AWS SES.<br \/>\nThe request is send everytime a mail is sent, and AWS SES is selected as the default adapter from the plugin settings (or the function to send email through AWS SES is directly invoked in the code).<br \/>\nHere is the <a href=\"https:\/\/aws.amazon.com\/service-terms\/\" rel=\"nofollow ugc\">Terms of Use<\/a> and <a href=\"https:\/\/docs.aws.amazon.com\/ses\/latest\/dg\/data-protection.html\" rel=\"nofollow ugc\">Privacy Policy<\/a> of the service.<\/p>\n<h4>Mailgun<\/h4>\n<p>This plugin connect\u2019s to Mailgun\u2019s API to send emails through Mailgun.<br \/>\nThe request is send everytime a mail is sent, and Mailgun is selected as the default adapter from the plugin settings (or the function to send email through Mailgun is directly invoked in the code).<br \/>\nHere is the <a href=\"https:\/\/www.mailgun.com\/legal\/terms\/\" rel=\"nofollow ugc\">Terms of Use<\/a> and <a href=\"https:\/\/www.mailgun.com\/legal\/privacy-policy\/\" rel=\"nofollow ugc\">Privacy Policy<\/a> of the service.<\/p>\n<h4>Telesign<\/h4>\n<p>This plugin connect\u2019s to Telesign\u2019s API to send SMS through Telesign.<br \/>\nThe request is send everytime the function to send SMS is invoked with the Adapter as Telesign or the default adapter is set as Telesign.<br \/>\nHere is the <a href=\"\/\/www.telesign.com\/telesign-terms-of-service\" rel=\"nofollow ugc\">Terms of Use<\/a> and <a href=\"https:\/\/www.telesign.com\/privacy-policy\" rel=\"nofollow ugc\">Privacy Policy<\/a> of the service.<\/p>\n<h4>Twilio<\/h4>\n<p>This plugin connect\u2019s to Twilio\u2019s API to send SMS through Twilio.<br \/>\nThe request is send everytime the function to send SMS is invoked with the Adapter as Twilio or the default adapter is set as Twilio.<br \/>\nHere is the <a href=\"https:\/\/www.twilio.com\/en-us\/legal\/tos\" rel=\"nofollow ugc\">Terms of Use<\/a> and <a href=\"https:\/\/www.twilio.com\/en-us\/legal\/privacy\" rel=\"nofollow ugc\">Privacy Policy<\/a> of the service.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Limitless Communication: All-in-one, super scalable, messaging Solution for WordPress.<\/p>\n","protected":false},"author":65,"featured_media":411061,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"All Path Messaging - \u8587\u6653\u6735\u63d2\u4ef6\u76ee\u5f55","description":"Limitless Communication: All-in-one, super scalable, messaging Solution for WordPress."},"footnotes":""},"categories":[1],"tags":[85,2685,20567,183],"class_list":["post-411060","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-email","tag-messaging","tag-push-notification","tag-sms"],"_links":{"self":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/411060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/comments?post=411060"}],"version-history":[{"count":0,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/411060\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media\/411061"}],"wp:attachment":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media?parent=411060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/categories?post=411060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/tags?post=411060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}