Fx.location:和發(fā)送消息有關(guān)的API
Channel決定消息發(fā)送的類(lèi)型
Channel channel = Channel.Service("appiD") //發(fā)送服務(wù)號(hào) Channel channel = Channel.ObjectSession("ObjectAPIName","ObjectId") //發(fā)送業(yè)務(wù)群
參數(shù)說(shuō)明:
參數(shù) | 說(shuō)明 |
---|---|
appId | 服務(wù)號(hào)的appId |
ObjectAPIName | 業(yè)務(wù)群所屬對(duì)象API Name |
ObjectId | 業(yè)務(wù)群所屬對(duì)象實(shí)例Id |
1、發(fā)送文本消息
定義:Fx.message.send(String textMessage , List<Integer> receiverIds , <Channel channel>)
data返回值類(lèi)型:String
例:通過(guò)appId為FSAID_bebd374的服務(wù)號(hào)向ID為1000的用戶(hù)發(fā)送一條文本消息-”這是一條文本消息“
Channel channel = Channel.Service("FSAID_bebd374") List receiverIds = [1000] //消息接收用戶(hù) def (error,date,errorMessage) = Fx.message.send("這是一條文本消息",receiverIds,channel)
2、發(fā)送卡片消息
定義:Fx.message.send(<Card card> , <List<Integer>receiverIds> , <Channel channel>)
data返回值類(lèi)型:String
例1:向ID為5cbd28e47cfed9ea0cca09e4的客戶(hù)群發(fā)送一個(gè)點(diǎn)擊跳轉(zhuǎn)對(duì)象詳情頁(yè)的卡片消息
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)對(duì)象的APIName(必填) objectId = "5cbd28e47cfed9ea0cca09e4" //跳轉(zhuǎn)對(duì)象的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)部平臺(tái)Web端跳轉(zhuǎn)(可選) innerDirectMobileUrl = "mobile" //卡片消息連接地址,紛享內(nèi)部平臺(tái)手機(jī)端端跳轉(zhuǎn)(可選) outerDirectUrl = "outer" //卡片消息連接地址,外部平臺(tái)跳轉(zhuǎn)(可選) } Channel channel = Channel.Service("FSAID_bebd374") //設(shè)置服務(wù)號(hào)ID List receiverIds = [1000] def (error,date,errorMessage) = Fx.message.send(card,receiverIds,channel)
注:1、向業(yè)務(wù)群發(fā)送消息時(shí),是通過(guò)客戶(hù)助手發(fā)送到群對(duì)話(huà)中,群成員全部可見(jiàn),receiverIds定義無(wú)效,但是參數(shù)必須存在
2、向服務(wù)號(hào)發(fā)送消息時(shí),如果receiverIds不在該服務(wù)號(hào)的可見(jiàn)范圍內(nèi),則不會(huì)發(fā)送成功
3、拋出異常信息
定義:Fx.message.throwErrorMessage(String errorMessage);
data返回值類(lèi)型:無(wú)
Fx.message.throwErrorMessage("函數(shù)異常")