Fx.location:和發(fā)送消息有關(guān)的API
Channel決定消息發(fā)送的類型
Channel channel = Channel.Service("appiD") //發(fā)送服務(wù)號 Channel channel = Channel.ObjectSession("ObjectAPIName","ObjectId") //發(fā)送業(yè)務(wù)群
參數(shù)說明:
參數(shù) | 說明 |
---|---|
appId | 服務(wù)號的appId |
ObjectAPIName | 業(yè)務(wù)群所屬對象API Name |
ObjectId | 業(yè)務(wù)群所屬對象實例Id |
1、發(fā)送文本消息
定義:Fx.message.send(String textMessage , List<Integer> receiverIds , <Channel channel>)
data返回值類型:String
例:通過appId為FSAID_bebd374的服務(wù)號向ID為1000的用戶發(fā)送一條文本消息-”這是一條文本消息“
Channel channel = Channel.Service("FSAID_bebd374") List receiverIds = [1000] //消息接收用戶 def (error,date,errorMessage) = Fx.message.send("這是一條文本消息",receiverIds,channel)
2、發(fā)送卡片消息
定義:Fx.message.send(<Card card> , <List<Integer>receiverIds> , <Channel channel>)
data返回值類型:String
例1:向ID為5cbd28e47cfed9ea0cca09e4的客戶群發(fā)送一個點擊跳轉(zhuǎn)對象詳情頁的卡片消息
def card = ObjectCard.builder { head { title = "head title" //卡片標(biāo)題(必填) } foot { title = "foot title" //卡片底部(必填) } body { content = "body content" //卡片內(nèi)容(必填) entries = [key: "value"] //卡片表格(可選) } objectApiName = "AccountObj" //跳轉(zhuǎn)對象的APIName(必填) objectId = "5cbd28e47cfed9ea0cca09e4" //跳轉(zhuǎn)對象的id(必填) } Channel channel = Channel.ObjectSession("AccountObj","5cbd28e47cfed9ea0cca09e4") List receiverIds = [1000] def (error,date,errorMessage) = Fx.message.send(card,receiverIds,channel)
例2:通用卡片,跳轉(zhuǎn)至其他地址
def card = Card.builder { head { title = "head title" } foot { title = "foot title" } body { content = "body content" entries = [key: "value"] } innerDirectWebUrl = "web" //卡片消息連接地址,紛享內(nèi)部平臺Web端跳轉(zhuǎn)(可選) innerDirectMobileUrl = "mobile" //卡片消息連接地址,紛享內(nèi)部平臺手機(jī)端端跳轉(zhuǎn)(可選) outerDirectUrl = "outer" //卡片消息連接地址,外部平臺跳轉(zhuǎn)(可選) } Channel channel = Channel.Service("FSAID_bebd374") //設(shè)置服務(wù)號ID List receiverIds = [1000] def (error,date,errorMessage) = Fx.message.send(card,receiverIds,channel)
注:1、向業(yè)務(wù)群發(fā)送消息時,是通過客戶助手發(fā)送到群對話中,群成員全部可見,receiverIds定義無效,但是參數(shù)必須存在
2、向服務(wù)號發(fā)送消息時,如果receiverIds不在該服務(wù)號的可見范圍內(nèi),則不會發(fā)送成功
3、拋出異常信息
定義:Fx.message.throwErrorMessage(String errorMessage);
data返回值類型:無
Fx.message.throwErrorMessage("函數(shù)異常")