Fx.message: API related to sending messages
1. Send text message
Fx.message.send(<String textMessage>, <List receiverIds>, <Channel channel>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| textMessage | String | text message |
| receiverIds | List | list of receiver ids |
| channel | Channel | message channel |
return type
APIResult
Return value description
String
Java example
Channel channel = Channel. Service("FSAID_bebd374");
List receiverIds = Lists.newArrayList(1000); //Message receiving users
APIResult ret = Fx.message.send("This is a text message", receiverIds, channel);
Groovy example
Channel channel = Channel. Service("FSAID_bebd374")
List receiverIds = [1000] //Message receiving users
def (error,date,errorMessage) = Fx.message.send("This is a text message",receiverIds,channel)
(1). Refer to Channel
2. Send card message
Fx.message.send(<Card card>, <List receiverIds>, <Channel channel>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| card | Card | Card Message |
| receiverIds | List | list of receiver ids |
| channel | Channel | message channel |
return type
APIResult
Return value description
String
Java example
Card.Head head = Card.Head.create();
head.setTitle("head title"); //Card title (required)
Card.Body body = Card.Body.create();
body.setContent("body content"); //Card content (required)
body.setEntries(Maps.of("a", 1)); //card form (optional)
Card.Foot foot = Card.Foot.create();
foot.setTitle("foot title"); //The bottom of the card (required)
ObjectCard.Builder builder = ObjectCard.Builder.create();
builder.setHead(head);
builder.setBody(body);
builder.setFoot(foot);
builder.setObjectApiName("AccountObj"); // APIName of the jump object (required)
builder.setObjectId("5cbd28e47cfed9ea0cca09e4"); //The id of the jump object (required)
Groovy example
def card = ObjectCard. builder {
head {
title = "head title" //card title (required)
}
foot {
title = "foot title" //Card bottom (required)
}
body {
content = "body content" //card content (required)
entries = [key: "value"] //card form (optional)
}
objectApiName = "AccountObj" // APIName of the jump object (required)
objectId = "5cbd28e47cfed9ea0cca09e4" //The id of the jump object (required)
}
Channel channel = Channel. Service("DSTX")
List receiverIds = [1000]
def (error, date, errorMessage) = Fx. message. send(card, receiverIds, channel)
3. Send CRM notification
Fx.message.sendNotice(<String title>, <String content>, <List receiverIds>, <Notice notice>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| title | String | CRM notification title |
| content | String | CRM notification content |
| receiverIds | List | list of receiver ids |
| notice | Notice | The type of notification, existing:
defaultNotice: ordinary notification, Notice notice = Notice.defaultNotice()
objectNotice: crm notification with a link to the object details page, you need to pass the object's apiName and DataId, Notice notice = Notice.objectNotice(String apiName, String dataId) |
return type
APIResult
Return value description
String
Java example
List receiverIds = Lists. newArrayList("1000", "1001");
Notice objectNotify = Notice.objectNotice("AccountObj", "5fa4de2f832a9d00012868b8");
final APIResult ret = Fx.message.sendNotice("This is also a title", "This is the content of the reminder", receiverIds, objectNotify);
if (ret. isError()) {
log.info(ret.message());
} else {
log.info(ret.getData());
}
Groovy example
List receiverIds = ['1000', '1001']
Notice objectNotify = Notice.objectNotice("AccountObj","5fa4de2f832a9d00012868b8")
def (Boolean error, String data, String errorMessage) = Fx.message.sendNotice("This is also a title", "This is the content of the reminder", receiverIds, objectNotify)
if (error) {
log. info(errorMessage)
} else {
log. info(data)
}
4. Throwing exception information
Fx.message.throwErrorMessage(<String errorMessage>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| errorMessage | String | exception message |
return type
void
Java example
Fx.message.throwErrorMessage("Function exception");
Groovy example
Fx.message.throwErrorMessage("Function exception")
5. Create enterprise credit business group
Fx.message.createTrustGroup(<String apiName>, <String dataId>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| apiName | String | object apiName |
| dataId | String | object data Id |
return type
APIResult
Return value description
Map (sessionId: business group Id, name: business group name)
Java example
APIResult ret = Fx. message. createTrustGroup("object_94QeC__c", "5dae6f48a5083da25946e68c");
if (ret. isError()) {
log.info(ret.message());
} else {
log.info(ret.getData());
}
Groovy example
def (Boolean error, Map data, String errorMessage) = Fx. message. createTrustGroup('object_94QeC__c', '5dae6f48a5083da25946e68c')
if(error) {
log. info(errorMessage)
} else {
log. info(data)
}
Precautions
- When using this function, you need to open the business group function of the object in the enterprise credit management of the management background and make relevant configurations
6. Send email
Fx.message.sendEmail(<List toList>, <String subject>, <String content>, <Boolean useSystemSend>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| toList | List | Recipient email list |
| subject | String | email subject |
| content | String | email body |
| useSystemSend | Boolean | Whether to use the system identity to send (true will use the current identity to send, if the current identity cannot be obtained, the system will send by default) |
return type
APIResult
Return value description
Java example
List toList = Lists.newArrayList("[email protected]");
String subject = "Custom function send_subject";
String content = "Custom function send_text";
APIResult ret = Fx. message. sendEmail(toList, subject, content, true);
Groovy example
List toList = ["[email protected]"]
String subject = "Custom function send_subject"
String content = "Custom function send_text"
def ret = Fx. message. sendEmail(toList, subject, content, true)
7. Send email, support CC and BCC
Fx.message.sendEmail(<EmailAttribute attribute>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| attribute | EmailAttribute | Email related information |
return type
APIResult
Return value description
Groovy example
List toList = ["[email protected]"]
String subject = "Custom function send_subject 112"
String content = "Custom function send_text 112"
List ccList = ["[email protected]"]
List bccList = []
boolean useSystemSend = true
EmailAttribute attribute = EmailAttribute. builder()
.toList(toList)
.ccList(ccList)
.bccList(bccList)
.subject(subject)
.content(content)
.useSystemSend(useSystemSend)
.build();
log. info(attribute)
def ret = Fx. message. sendEmail(attribute)
log. info(ret)
(1). Refer to EmailAttribute
8. Send email using email template and data
Fx.message.sendEmailByTemplate(<String templateId>, <String objectId>, <List toList>, <Boolean useSystemSend>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| templateId | String | template id |
| objectId | String | object data id |
| toList | List | Recipient email list |
| useSystemSend | Boolean | Whether to use system mailbox |
return type
APIResult
Return value description
Java example
APIResult ret = Fx.message.sendEmailByTemplate("6142e00f16bd944a7c878b77", "609ce6c2131e59000172ecfb", Lists.newArrayList("[email protected]"), true);
Groovy example
def ret = Fx.message.sendEmailByTemplate("6142e00f16bd944a7c878b77", "609ce6c2131e59000172ecfb", ["[email protected]"], true)
9. Use email templates and data to send emails, support CC and BCC
Fx.message.sendEmailByTemplate(<EmailAttribute attribute>)
Parameter Description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| attribute | EmailAttribute | Email related information |
return type
APIResult
Return value description
Groovy example
List toList = ["[email protected]"]
List ccList = ["[email protected]"]
List bccList = []
boolean useSystemSend = true
EmailAttribute attribute = EmailAttribute. builder()
.toList(toList)
.ccList(ccList)
.bccList(bccList)
.templateId("6142e00f16bd944a7c878b77")
.objectId("609ce6c2131e59000172ecfb")
.useSystemSend(useSystemSend)
.build();
def ret = Fx.message.sendEmailByTemplate(attribute)
log. info(ret)
Reference class com.fxiaoke.functions.model.Channel
1. Qixin Service Account Channel
Channel. Service(<String appId>)
Parameter Description
| parameter| Type | Description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| appId | String | appId of the service account |
return type
Channel
Return value description
Channel
Java example
Channel channel = Channel.Service("appiD"); //send service number
Groovy example:
Channel channel = Channel.Service("appiD") //send service number
Reference class com.fxiaoke.functions.model.EmailAttribute
field description
| parameter | type | description |
| ------------ | ------------ | ----------------------- ----------------------------------------- |
| toList | List | Recipient email list |
| ccList | List | CC Mailbox List |
| bccList | List | Bcc Mailbox List |
| subject | String | email subject |
| content | String | email body |
| useSystemSend | Boolean | Whether to use the system identity to send (true will use the current identity to send, if the current identity cannot be obtained, the system will be used to send by default), the default is true |
| templateId | String | template id |
| objectId | String | object data id |