이 페이지에서는 메시징 구성 요소를 사용하여 웹 사이트에 메시징 기능을 포함하는 작업에 대한 세부 사항을 설명합니다.
메시지 작성
resourceType | social/messaging/components/hbs/composemessage |
clientlibs | cq.social.hbs.messaging |
템플릿 | /libs/social/messaging/components/hbs/composemessage/composemessage.hbs |
css | /libs/social/messaging/components/hbs/composemessage/clientlibs/composemessage.css |
속성 | 메시징 구성 을 참조하십시오. |
관리 구성 | 메시징 구성 |
메시지 목록
(받은 편지함, 전송 및 휴지통의 경우)
resourceType | social/messaging/components/hbs/messagebox |
clientlibs | cq.social.hbs.messaging |
템플릿 | /libs/social/messaging/components/hbs/messagebox/messagebox.hbs |
css | /libs/social/messaging/components/hbs/messagebox/clientlibs/messagebox.css |
속성 | 메시징 구성 을 참조하십시오. |
관리 구성 | 메시징 구성 |
클라이언트측 사용자 지정도 참조하십시오.
String 매개 변수는 다음 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)
에 관리자로 로그인합니다.
/apps/engage/install
에서 다음과 같은 임의 이름을 사용하여 bundle node
을 만듭니다.
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 서비스가 구성되어 있는지 확인합니다.
데모 사용자로 로그인하고 다른 사용자에게 이메일을 보냅니다.
수신자가 새 메시지에 대한 이메일을 받습니다.
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();
}
}
}