From 543cfa89b9d63b76707abe6e125fe39472298cdc Mon Sep 17 00:00:00 2001 From: Jerry Date: Tue, 19 Dec 2023 17:29:13 +0800 Subject: [PATCH] feat(message): add reactionMessage and deleteReactionMessage (#62) * feat(message): add reactionMessage and deleteReactionMessage * feat(message): move emojis to emoji.go * fix: lint issues --------- Co-authored-by: David Zhang --- README.md | 3 + README_zhCN.md | 3 + api_message.go | 37 +++++++++ api_message_test.go | 17 +++++ emoji.go | 179 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 239 insertions(+) create mode 100644 emoji.go diff --git a/README.md b/README.md index e7e9ccf..526e69d 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,9 @@ For Chat Bot, we can send simple messages with the following method: - `PostTextMentionAll` - `PostImage` - `PostShareChatCard` +- `ReplyMessage` +- `ReactionMessage` +- `DeleteReactionMessage` Basic message examples: [examples/basic-message](https://github.com/go-lark/examples/tree/main/basic-message) diff --git a/README_zhCN.md b/README_zhCN.md index a13e5fa..cee3216 100644 --- a/README_zhCN.md +++ b/README_zhCN.md @@ -122,6 +122,9 @@ resp, err := bot.GetTenantAccessTokenInternal(true) - `PostTextMentionAll` - `PostImage` - `PostShareChatCard` +- `ReplyMessage` +- `ReactionMessage` +- `DeleteReactionMessage` 参考实例:[基本消息](https://github.com/go-lark/examples/tree/main/basic-message)。 diff --git a/api_message.go b/api_message.go index a41703e..275857d 100644 --- a/api_message.go +++ b/api_message.go @@ -5,6 +5,8 @@ import "fmt" const ( messageURL = "/open-apis/im/v1/messages?receive_id_type=%s" replyMessageURL = "/open-apis/im/v1/messages/%s/reply" + reactionsMessageURL = "/open-apis/im/v1/messages/%s/reactions" + deleteReactionsMessageURL = "/open-apis/im/v1/messages/%s/reactions/%s" getMessageURL = "/open-apis/im/v1/messages/%s" updateMessageURL = "/open-apis/im/v1/messages/%s" recallMessageURL = "/open-apis/im/v1/messages/%s" @@ -68,6 +70,22 @@ type IMMessage struct { Body IMBody } +// ReactionResponse . +type ReactionResponse struct { + BaseResponse + Data struct { + ReactionID string `json:"reaction_id"` + Operator struct { + OperatorID string `json:"operator_id"` + OperatorType string `json:"operator_type"` + ActionTime string `json:"action_time"` + } `json:"operator"` + ReactionType struct { + EmojiType EmojiType `json:"emoji_type"` + } `json:"reaction_type"` + } `json:"data"` +} + // GetMessageResponse . type GetMessageResponse struct { BaseResponse @@ -256,6 +274,25 @@ func (bot Bot) ReplyMessage(om OutcomingMessage) (*PostMessageResponse, error) { return &respData, err } +// ReactionMessage reactions messages +func (bot Bot) ReactionMessage(messageID string, emojiType EmojiType) (*ReactionResponse, error) { + req := map[string]interface{}{ + "reaction_type": map[string]interface{}{ + "emoji_type": emojiType, + }, + } + var respData ReactionResponse + err := bot.PostAPIRequest("ReactionMessage", fmt.Sprintf(reactionsMessageURL, messageID), true, req, &respData) + return &respData, err +} + +// DeleteReactionMessage delete reactions messages +func (bot Bot) DeleteReactionMessage(messageID string, reactionID string) (*ReactionResponse, error) { + var respData ReactionResponse + err := bot.DeleteAPIRequest("DeleteReactionMessage", fmt.Sprintf(deleteReactionsMessageURL, messageID, reactionID), true, nil, &respData) + return &respData, err +} + // UpdateMessage update message card func (bot Bot) UpdateMessage(messageID string, om OutcomingMessage) (*UpdateMessageResponse, error) { if om.MsgType != MsgInteractive { diff --git a/api_message_test.go b/api_message_test.go index 8cc95a5..c79e781 100644 --- a/api_message_test.go +++ b/api_message_test.go @@ -445,3 +445,20 @@ func TestPinMessages(t *testing.T) { } } } + +func TestReactionMessage(t *testing.T) { + msg := NewMsgBuffer(MsgText) + om := msg.BindEmail(testUserEmail).Text("hello, world").Build() + resp, err := bot.PostMessage(om) + if assert.NoError(t, err) { + messageID := resp.Data.MessageID + resp, err := bot.ReactionMessage(messageID, EmojiTypeOK) + if assert.NoError(t, err) { + assert.Equal(t, 0, resp.Code) + assert.Equal(t, EmojiTypeOK, resp.Data.ReactionType.EmojiType) + deleteReactionResp, err := bot.DeleteReactionMessage(messageID, resp.Data.ReactionID) + assert.NoError(t, err) + assert.Equal(t, 0, deleteReactionResp.Code) + } + } +} diff --git a/emoji.go b/emoji.go new file mode 100644 index 0000000..07d449d --- /dev/null +++ b/emoji.go @@ -0,0 +1,179 @@ +package lark + +// EmojiType . +type EmojiType string + +// Emoji types +const ( + EmojiTypeOK EmojiType = "OK" + EmojiTypeTHUMBSUP EmojiType = "THUMBSUP" + EmojiTypeTHANKS EmojiType = "THANKS" + EmojiTypeMUSCLE EmojiType = "MUSCLE" + EmojiTypeFINGERHEART EmojiType = "FINGERHEART" + EmojiTypeAPPLAUSE EmojiType = "APPLAUSE" + EmojiTypeFISTBUMP EmojiType = "FISTBUMP" + EmojiTypeJIAYI EmojiType = "JIAYI" + EmojiTypeDONE EmojiType = "DONE" + EmojiTypeSMILE EmojiType = "SMILE" + EmojiTypeBLUSH EmojiType = "BLUSH" + EmojiTypeLAUGH EmojiType = "LAUGH" + EmojiTypeSMIRK EmojiType = "SMIRK" + EmojiTypeLOL EmojiType = "LOL" + EmojiTypeFACEPALM EmojiType = "FACEPALM" + EmojiTypeLOVE EmojiType = "LOVE" + EmojiTypeWINK EmojiType = "WINK" + EmojiTypePROUD EmojiType = "PROUD" + EmojiTypeWITTY EmojiType = "WITTY" + EmojiTypeSMART EmojiType = "SMART" + EmojiTypeSCOWL EmojiType = "SCOWL" + EmojiTypeTHINKING EmojiType = "THINKING" + EmojiTypeSOB EmojiType = "SOB" + EmojiTypeCRY EmojiType = "CRY" + EmojiTypeERROR EmojiType = "ERROR" + EmojiTypeNOSEPICK EmojiType = "NOSEPICK" + EmojiTypeHAUGHTY EmojiType = "HAUGHTY" + EmojiTypeSLAP EmojiType = "SLAP" + EmojiTypeSPITBLOOD EmojiType = "SPITBLOOD" + EmojiTypeTOASTED EmojiType = "TOASTED" + EmojiTypeGLANCE EmojiType = "GLANCE" + EmojiTypeDULL EmojiType = "DULL" + EmojiTypeINNOCENTSMILE EmojiType = "INNOCENTSMILE" + EmojiTypeJOYFUL EmojiType = "JOYFUL" + EmojiTypeWOW EmojiType = "WOW" + EmojiTypeTRICK EmojiType = "TRICK" + EmojiTypeYEAH EmojiType = "YEAH" + EmojiTypeENOUGH EmojiType = "ENOUGH" + EmojiTypeTEARS EmojiType = "TEARS" + EmojiTypeEMBARRASSED EmojiType = "EMBARRASSED" + EmojiTypeKISS EmojiType = "KISS" + EmojiTypeSMOOCH EmojiType = "SMOOCH" + EmojiTypeDROOL EmojiType = "DROOL" + EmojiTypeOBSESSED EmojiType = "OBSESSED" + EmojiTypeMONEY EmojiType = "MONEY" + EmojiTypeTEASE EmojiType = "TEASE" + EmojiTypeSHOWOFF EmojiType = "SHOWOFF" + EmojiTypeCOMFORT EmojiType = "COMFORT" + EmojiTypeCLAP EmojiType = "CLAP" + EmojiTypePRAISE EmojiType = "PRAISE" + EmojiTypeSTRIVE EmojiType = "STRIVE" + EmojiTypeXBLUSH EmojiType = "XBLUSH" + EmojiTypeSILENT EmojiType = "SILENT" + EmojiTypeWAVE EmojiType = "WAVE" + EmojiTypeWHAT EmojiType = "WHAT" + EmojiTypeFROWN EmojiType = "FROWN" + EmojiTypeSHY EmojiType = "SHY" + EmojiTypeDIZZY EmojiType = "DIZZY" + EmojiTypeLOOKDOWN EmojiType = "LOOKDOWN" + EmojiTypeCHUCKLE EmojiType = "CHUCKLE" + EmojiTypeWAIL EmojiType = "WAIL" + EmojiTypeCRAZY EmojiType = "CRAZY" + EmojiTypeWHIMPER EmojiType = "WHIMPER" + EmojiTypeHUG EmojiType = "HUG" + EmojiTypeBLUBBER EmojiType = "BLUBBER" + EmojiTypeWRONGED EmojiType = "WRONGED" + EmojiTypeHUSKY EmojiType = "HUSKY" + EmojiTypeSHHH EmojiType = "SHHH" + EmojiTypeSMUG EmojiType = "SMUG" + EmojiTypeANGRY EmojiType = "ANGRY" + EmojiTypeHAMMER EmojiType = "HAMMER" + EmojiTypeSHOCKED EmojiType = "SHOCKED" + EmojiTypeTERROR EmojiType = "TERROR" + EmojiTypePETRIFIED EmojiType = "PETRIFIED" + EmojiTypeSKULL EmojiType = "SKULL" + EmojiTypeSWEAT EmojiType = "SWEAT" + EmojiTypeSPEECHLESS EmojiType = "SPEECHLESS" + EmojiTypeSLEEP EmojiType = "SLEEP" + EmojiTypeDROWSY EmojiType = "DROWSY" + EmojiTypeYAWN EmojiType = "YAWN" + EmojiTypeSICK EmojiType = "SICK" + EmojiTypePUKE EmojiType = "PUKE" + EmojiTypeBETRAYED EmojiType = "BETRAYED" + EmojiTypeHEADSET EmojiType = "HEADSET" + EmojiTypeEatingFood EmojiType = "EatingFood" + EmojiTypeMeMeMe EmojiType = "MeMeMe" + EmojiTypeSigh EmojiType = "Sigh" + EmojiTypeTyping EmojiType = "Typing" + EmojiTypeLemon EmojiType = "Lemon" + EmojiTypeGet EmojiType = "Get" + EmojiTypeLGTM EmojiType = "LGTM" + EmojiTypeOnIt EmojiType = "OnIt" + EmojiTypeOneSecond EmojiType = "OneSecond" + EmojiTypeVRHeadset EmojiType = "VRHeadset" + EmojiTypeYouAreTheBest EmojiType = "YouAreTheBest" + EmojiTypeSALUTE EmojiType = "SALUTE" + EmojiTypeSHAKE EmojiType = "SHAKE" + EmojiTypeHIGHFIVE EmojiType = "HIGHFIVE" + EmojiTypeUPPERLEFT EmojiType = "UPPERLEFT" + EmojiTypeThumbsDown EmojiType = "ThumbsDown" + EmojiTypeSLIGHT EmojiType = "SLIGHT" + EmojiTypeTONGUE EmojiType = "TONGUE" + EmojiTypeEYESCLOSED EmojiType = "EYESCLOSED" + EmojiTypeRoarForYou EmojiType = "RoarForYou" + EmojiTypeCALF EmojiType = "CALF" + EmojiTypeBEAR EmojiType = "BEAR" + EmojiTypeBULL EmojiType = "BULL" + EmojiTypeRAINBOWPUKE EmojiType = "RAINBOWPUKE" + EmojiTypeROSE EmojiType = "ROSE" + EmojiTypeHEART EmojiType = "HEART" + EmojiTypePARTY EmojiType = "PARTY" + EmojiTypeLIPS EmojiType = "LIPS" + EmojiTypeBEER EmojiType = "BEER" + EmojiTypeCAKE EmojiType = "CAKE" + EmojiTypeGIFT EmojiType = "GIFT" + EmojiTypeCUCUMBER EmojiType = "CUCUMBER" + EmojiTypeDrumstick EmojiType = "Drumstick" + EmojiTypePepper EmojiType = "Pepper" + EmojiTypeCANDIEDHAWS EmojiType = "CANDIEDHAWS" + EmojiTypeBubbleTea EmojiType = "BubbleTea" + EmojiTypeCoffee EmojiType = "Coffee" + EmojiTypeYes EmojiType = "Yes" + EmojiTypeNo EmojiType = "No" + EmojiTypeOKR EmojiType = "OKR" + EmojiTypeCheckMark EmojiType = "CheckMark" + EmojiTypeCrossMark EmojiType = "CrossMark" + EmojiTypeMinusOne EmojiType = "MinusOne" + EmojiTypeHundred EmojiType = "Hundred" + EmojiTypeAWESOMEN EmojiType = "AWESOMEN" + EmojiTypePin EmojiType = "Pin" + EmojiTypeAlarm EmojiType = "Alarm" + EmojiTypeLoudspeaker EmojiType = "Loudspeaker" + EmojiTypeTrophy EmojiType = "Trophy" + EmojiTypeFire EmojiType = "Fire" + EmojiTypeBOMB EmojiType = "BOMB" + EmojiTypeMusic EmojiType = "Music" + EmojiTypeXmasTree EmojiType = "XmasTree" + EmojiTypeSnowman EmojiType = "Snowman" + EmojiTypeXmasHat EmojiType = "XmasHat" + EmojiTypeFIREWORKS EmojiType = "FIREWORKS" + EmojiType2022 EmojiType = "2022" + EmojiTypeREDPACKET EmojiType = "REDPACKET" + EmojiTypeFORTUNE EmojiType = "FORTUNE" + EmojiTypeLUCK EmojiType = "LUCK" + EmojiTypeFIRECRACKER EmojiType = "FIRECRACKER" + EmojiTypeStickyRiceBalls EmojiType = "StickyRiceBalls" + EmojiTypeHEARTBROKEN EmojiType = "HEARTBROKEN" + EmojiTypePOOP EmojiType = "POOP" + EmojiTypeStatusFlashOfInspiration EmojiType = "StatusFlashOfInspiration" + EmojiType18X EmojiType = "18X" + EmojiTypeCLEAVER EmojiType = "CLEAVER" + EmojiTypeSoccer EmojiType = "Soccer" + EmojiTypeBasketball EmojiType = "Basketball" + EmojiTypeGeneralDoNotDisturb EmojiType = "GeneralDoNotDisturb" + EmojiTypeStatusPrivateMessage EmojiType = "Status_PrivateMessage" + EmojiTypeGeneralInMeetingBusy EmojiType = "GeneralInMeetingBusy" + EmojiTypeStatusReading EmojiType = "StatusReading" + EmojiTypeStatusInFlight EmojiType = "StatusInFlight" + EmojiTypeGeneralBusinessTrip EmojiType = "GeneralBusinessTrip" + EmojiTypeGeneralWorkFromHome EmojiType = "GeneralWorkFromHome" + EmojiTypeStatusEnjoyLife EmojiType = "StatusEnjoyLife" + EmojiTypeGeneralTravellingCar EmojiType = "GeneralTravellingCar" + EmojiTypeStatusBus EmojiType = "StatusBus" + EmojiTypeGeneralSun EmojiType = "GeneralSun" + EmojiTypeGeneralMoonRest EmojiType = "GeneralMoonRest" + EmojiTypePursueUltimate EmojiType = "PursueUltimate" + EmojiTypePatient EmojiType = "Patient" + EmojiTypeAmbitious EmojiType = "Ambitious" + EmojiTypeCustomerSuccess EmojiType = "CustomerSuccess" + EmojiTypeResponsible EmojiType = "Responsible" + EmojiTypeReliable EmojiType = "Reliable" +)