このページでは、メッセージングコンポーネントを使用してメッセージング機能を Web サイトに組み込む方法の詳細をまとめています。
メッセージを作成
resourceType | social/messaging/components/hbs/composemessage |
clientllibs | cq.social.hbs.messaging |
テンプレート | /libs/social/messaging/components/hbs/composemessage/composemessage.hbs |
css | /libs/social/messaging/components/hbs/composemessage/clientlibs/composemessage.css |
properties | 詳しくは、 メッセージの設定 |
管理設定 | メッセージの設定 |
メッセージリスト
(インボックス、送信済み、ごみ箱)
resourceType | social/messaging/components/hbs/messagebox |
clientllibs | cq.social.hbs.messaging |
テンプレート | /libs/social/messaging/components/hbs/messagebox/messagebox.hbs |
css | /libs/social/messaging/components/hbs/messagebox/clientlibs/messagebox.css |
プロパティ | 詳しくは、 メッセージの設定 |
管理設定 | メッセージの設定 |
クライアント側のカスタマイズも参照してください。
String パラメーターは必ず指定する必要があります not 次の MessageBuilder メソッドの末尾にスラッシュ「/」が含まれている場合:
setInboxPath
()setSentItemsPath
()次に例を示します。
valid: mb.setInboxPath( "/mail/inbox" );
not valid: mb.setInboxPath( "/mail/inbox/" );
ウィザードを使用して作成されたコミュニティサイト構造には、選択するとメッセージング機能が含まれます。 詳しくは、 User Management
設定 コミュニティサイトコンソール.
ソーシャルメッセージ機能では、操作に関するイベント ( 例えば、 send
, marking read
, marking delete
. これらのイベントを取得し、イベントに含まれるデータに対して実行されるアクションを取得できます。
次の例は、 message sent
イベントを送信し、 Day CQ Mail Service
.
サーバー側サンプルスクリプトを試すには、開発環境と OSGi バンドルを構築する機能が必要です。
に管理者としてログインします。 [CRXDE|Lite](https://localhost:4502/crx/de)
.
の作成 bundle node
in /apps/engage/install
に次のような任意の名前を付けます。
com.engage.media.social.messaging.MessagingNotification
com.engage.media.social.messaging.notification
に移動します。 /apps/engage/install/com.engage.media.social.messaging.MessagingNotification/src/main/java/com/engage/media/social/messaging/notification
、次に、
Activator.java
クラスが自動的に作成されました。MessageEventHandler.java
.MessageEventHandler.java
.「すべて保存」をクリックします。
に移動します。 /apps/engage/install/com.engage.media.social.messaging.MessagingNotification/com.engage.media.social.messaging.MessagingNotification.bnd
をクリックし、 MessageEventHandler.java
コード。
バンドルをビルドします。
確認 Day CQ Mail Service
OSGi サービスが設定されている。
デモユーザーとしてログインし、別のユーザーに電子メールを送信します。
受信者に、新しいメッセージに関する E メールが届きます。
package com.engage.media.social.messaging.notification;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.apache.felix.scr.annotations.Reference;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.Resource;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
import org.apache.commons.mail.HtmlEmail;
import java.util.List;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.adobe.cq.social.messaging.api.Message;
import com.adobe.cq.social.messaging.api.MessagingEvent;
import com.day.cq.mailer.MessageGatewayService;
import com.day.cq.mailer.MessageGateway;
@Component(immediate=true)
@Service(EventHandler.class)
@Properties({
@Property(name = "event.topics", value = "com/adobe/cq/social/message")
})
public class MessagingEventHandler implements EventHandler {
private Logger logger = LoggerFactory.getLogger(MessagingEventHandler.class);
@Reference
ResourceResolverFactory resourceResolverFactory;
@Reference
private MessageGatewayService messageGatewayService;
ResourceResolver resourceResolver=null;
MessageGateway messageGateway=null;
public void sendMail(String from, String to,String subject, String content){
Email email = new SimpleEmail();
messageGateway = messageGatewayService.getGateway(SimpleEmail.class);
try {
email.addTo(to);
email.addReplyTo(from);
email.setFrom(from);
email.setMsg(content);
email.setSubject(subject);
messageGateway.send(email);
} catch(EmailException ex) {
logger.error("MessageNotificaiton : Error sending email : "+ex.getMessage());
}
logger.info("**** MessageNotification **** Mail sent to " + to);
}
public void handleEvent(Event event) {
//Get Message Path and originator User's ID from event
String messagePath = (String) event.getProperty("path");
String senderId = (String) event.getProperty("userId");
MessagingEvent.MessagingActions action = (MessagingEvent.MessagingActions) event.getProperty("action");
try{
if(MessagingEvent.MessagingActions.MessageSent.equals(action)){
resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
//Read message
Resource resource = resourceResolver.getResource(messagePath);
Message msg = resource.adaptTo(Message.class);
//Get list of recipient Ids from message
//For Getting Started Tutorial, Id is same as email. If that is not the case in your site,
//an additional step is needed to retrieve the email for the Id
List<String> reclist = msg.getRecipientIdList();
for(int i=0;i<reclist.size();i++){
//Send Email using Mailing Service
sendMail("admin@cqadmin.qqq",reclist.get(i),"New message on Getting Started Tutorial", "Hi\nYou have received a new message from " + senderId + ". To read it, sign in to Getting Started Tutorial.\n\n-Engage Admin");
}
}
} catch(Exception ex){
logger.error("Error getting message info : " + ex.getMessage());
} finally {
resourceResolver.close();
}
}
}