Send automated notifications for new content using a custom function

This tutorial explains how to execute a custom function within a specific process. The function can send notifications and register data outside the timing of a standard function.

Below, we implement an automatic notification system for new content.

Creating the custom function

First, create the custom function.

1. Go to the function list screen

In the left sidebar menu, click [Operation] -> [Function].

fetched from Gyazo

2. Go to the function editor screen

Click the [Add] button at the upper right corner of the screen.

fetched from Gyazo

fetched from Gyazo

3. Enter a title and a slug

To create your function, first enter a title and a slug:

  • Title: Send e-mail when content is added in ID29
  • Slug: sample1_trigger

The title and slug have to be unique (i.e., two functions cannot have the same title and slug). For example, you can name the function after the endpoint used to implement it.

fetched from Gyazo

4. Specify the components that use the function

Next, fill out the "Used by component(s)" field as follows:

  • Trigger: After adding content
  • Text field*:29

fetched from Gyazo

*Fill in the text field with the ID of the topic group you want to implement the function for. You can find the topic group ID on the content structure list screen. In this example, 29 is the ID of the group created in the Creating topic group(s) tutorial. Adding new content to the group will trigger the execution of the function.

5. Write the code for the function

After specifying the components, write the code to send an automated e-mail to the editor. First, compose the subject and body of the e-mail. You can use the following variable:

variable nametypedescription
$topicsDataobjectContent data

Copy the following code into your editor:

{* Title *}
{assign var=mail_subject value=$topicsData.subject}
{* Body *}
{capture name=mail_body}
New content has been added.  

For details, please check below:
{$smarty.const.ROOT_MNG_URL}/management/topics/topics_edit/?topics_id={$topicsData.topics_id}
{/capture}
{assign var=mail_body value=$smarty.capture.mail_body}

fetched from Gyazo

Next, implement the e-mail delivery process. Copy the following code into your editor, replacing YOUR_MAIL_ADDRESS@example.com with your actual e-mail address:

{sendmail 
 to='YOUR_MAIL_ADDRESS@example.com'
 subject=$mail_subject
 contents=$mail_body}

fetched from Gyazo

6. Save the function

Now you have finished creating the function. Click [Add] to save these settings.

fetched from Gyazo

Verifying the notification delivery

To verify if the above function works, follow the steps below:

In the left sidebar menu, click [Content structure]. On the content structure list screen, click [Add] next to the group you created the function for.
fetched from Gyazo

On the content editor screen, enter the topic contents and click [Add].
fetched from Gyazo

The system will send the notification e-mail to the address specified in the function.
fetched from Gyazo

Troubleshooting

If you did not receive the e-mail notification, refer to the FAQ below:

Note

Two functions cannot share the same caller. This tutorial configured the following "Used by component(s)":

  • Trigger: After adding content
  • Text field:29

Please ensure that you do not use these settings for other functions.

If you have any other questions, please use our contact form or Slack workspace.