이 페이지에서는 메시징 구성 요소를 사용하여 웹 사이트에 메시징 기능을 포함하는 작업에 대한 세부 사항을 문서화합니다.
메시지 작성
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 |
속성 | 메시징 구성 참조 |
관리 구성 | 메시징 구성 |
클라이언트측 사용자 지정도 참조하십시오.
서비스에 대한 메시지 API
String 매개 변수는 다음 MessageBuilder 메서드에 대해 후행 슬래시 "/"를 포함하지 않아야 합니다.
setInboxPath
()setSentItemsPath
()예:
valid: mb.setInboxPath( "/mail/inbox" );
not valid: mb.setInboxPath( "/mail/inbox/" );
마법사를 사용하여 만든 커뮤니티 사이트 구조에는 선택한 경우 메시징 기능이 포함됩니다. 커뮤니티 사이트 콘솔의 User Management
설정을 참조하십시오.
소셜 메시징 기능은 작업(예: send
, marking read
, marking delete
)에 대한 이벤트를 throw합니다. 이러한 이벤트를 catch할 수 있으며 이벤트에 포함된 데이터에 대해 수행되는 작업을 수행할 수 있습니다.
다음 예제는 message sent
이벤트를 수신하고 Day CQ Mail Service
을 사용하여 모든 메시지 수신자에게 이메일을 보내는 이벤트 핸들러의 예입니다.
서버측 샘플 스크립트를 사용하려면 개발 환경과 OSGi 번들을 빌드하는 기능이 필요합니다.
[CRXDE|Lite](http://localhost:4502/crx/de)
에 관리자로 로그인합니다.
/apps/engage/install
에 다음과 같은 임의 이름으로 bundle node
을 만듭니다.
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();
}
}
}