Recently I built a small demo to guide the local partners in China how to extend WordPress using Kyma in a step-by-step way.
The demo is mainly built based on the great blog written by Piotr Bochynski:
And open SAP course: Kyma – A Flexible Way to Connect and Extend Applications
The simple scenario used in the demo is to replicate the blog originally written in WordPress to many different other social media platforms, such as Facebook, Twitter, YouTube etc.
Since I built the demo specially for Chinese partners, instead of using Twitter ( Twitter is not accessible in China mainland due to political reasons ), I choose Wechat (similar to WhatsApp) instead.
I have recorded a video for your reference.
Below are the detail steps to finish this demo.
1. Setup WordPress and install the Kyma plugin.
You can download source code from WordPress website or from my github.
Besides WordPress itself, you have to setup PHP environment and SQL server as well in order to make WordPress running in your local laptop.
For me I choose WAMP server in windows environment which has PHP and SQL server embedded in a bundle.
Put the whole source code of WordPress to the www folder of WAMP server, and you should be able to see the WordPress admin page from url localhost:8080/Wordpress/wp-admin
Install Kyma plugin for WordPress from url:
Once installation finishes, an additional setting menu is visible.
This setting page is used to configure Kyma endpoint, and users can specify which events & API are supposed to expose to Kyma.
As now we don’t have application created in Kyma, so just leave it there.
2. Create a new application within a given namespace:
Open the created application, press “Connect Application” button, copy the url in the dialog into the Connect field of WordPress Kyma plugin.
And click “Connect” button, and there is some magic occurred under the hood. More detailed explanation about what happens after this button is pressed could be found from another article of mine.
If everything works well, you should see the successfully connected notification: “Connection to Kyma works”.
Now register the post.published event via WordPress Action Hook publish_post, which is a standard hook of WordPress fired automatically when a new post is published. With the help of WordPress Kyma plugin, the post.published event will be sent to connected Kyma instance at that time.
3. Go back to Kyma, find the exposed WordPress service in Service Catalog:
Then create a new service instance based on it:
Create a new Lambda function:
Choose nodejs as Lambda function implementation type:
For Function Trigger selection, choose post.published from drop down list:
In the source code of Lambda function, just call Wechat’s API to forward the post content parsed from event argument event.data to the dedicated Wechat user.
Never forget to maintain dependencies if external library is used in the implementation( the same syntax as package.json in normal nodejs project).
Create a service binding as last step to bind the Lambda function with WordPress service instance. And that’s all.
Now we can test the integration scenario: post a new blog in WordPress and press publish button:
If we debug into WordPress, we can figure out how the WordPress post content is dispatched to Kyma:
And go to Lambda function pages and click “Show Logs” to display the log:
The published post content from WordPress could be found in the log as expected.
Switch to the Wechat application in my mobile phone, and I received the post content and delegated by Kyma, which is originally sent from WordPress.
This is the orchestration scenario I would like to introduce, among WordPress, SAP Kyma and Wechat.