-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce chat.update bindings #112
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,40 +2,21 @@ | |
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
---------------------------------------------------------------------- | ||
|
||
---------------------------------------------------------------------- | ||
|
||
-- | | ||
-- Module: Web.Slack.Chat | ||
-- Description: | ||
module Web.Slack.Chat | ||
( PostMsg (..), | ||
PostMsgReq (..), | ||
mkPostMsgReq, | ||
PostMsgRsp (..), | ||
UpdateReq (..), | ||
mkUpdateReq, | ||
UpdateRsp (..), | ||
) | ||
where | ||
|
||
-- FIXME: Web.Slack.Prelude | ||
|
||
-- aeson | ||
|
||
-- base | ||
|
||
-- deepseq | ||
import Control.DeepSeq (NFData) | ||
import Data.Aeson.TH | ||
-- http-api-data | ||
|
||
-- slack-web | ||
|
||
-- text | ||
import Data.Text (Text) | ||
import GHC.Generics (Generic) | ||
import Web.FormUrlEncoded | ||
import Web.Slack.Conversation (ConversationId) | ||
import Web.Slack.Prelude | ||
import Web.Slack.Util | ||
import Prelude | ||
|
||
data PostMsg = PostMsg | ||
{ postMsgText :: Text | ||
|
@@ -59,7 +40,9 @@ $(deriveJSON (jsonOpts "postMsg") ''PostMsg) | |
|
||
data PostMsgReq = PostMsgReq | ||
{ postMsgReqChannel :: Text | ||
, postMsgReqText :: Text | ||
, postMsgReqText :: Maybe Text | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually Maybe in the API since you can have a message with blocks and no text. |
||
-- ^ One of 'postMsgReqText', 'postMsgReqAttachments', or 'postMsgReqBlocks' | ||
-- is required. | ||
, postMsgReqParse :: Maybe Text | ||
, postMsgReqLinkNames :: Maybe Bool | ||
, postMsgReqAttachments :: Maybe Text | ||
|
@@ -90,7 +73,7 @@ mkPostMsgReq :: | |
mkPostMsgReq channel text = | ||
PostMsgReq | ||
{ postMsgReqChannel = channel | ||
, postMsgReqText = text | ||
, postMsgReqText = Just text | ||
, postMsgReqParse = Nothing | ||
, postMsgReqLinkNames = Nothing | ||
, postMsgReqAttachments = Nothing | ||
|
@@ -106,11 +89,60 @@ mkPostMsgReq channel text = | |
} | ||
|
||
data PostMsgRsp = PostMsgRsp | ||
{ postMsgRspTs :: String | ||
{ postMsgRspTs :: Text | ||
Comment on lines
-109
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a breaking change, but it is silly that this was a String to begin with. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will you be bumping the version number? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am going to write a changelog Soon and release 1.5 (current version is 0.5), but not in this PR. |
||
, postMsgRspMessage :: PostMsg | ||
} | ||
deriving stock (Eq, Generic, Show) | ||
|
||
instance NFData PostMsgRsp | ||
|
||
$(deriveFromJSON (jsonOpts "postMsgRsp") ''PostMsgRsp) | ||
|
||
-- | <https://api.slack.com/methods/chat.update> | ||
data UpdateReq = UpdateReq | ||
{ updateReqChannel :: ConversationId | ||
, updateReqTs :: Text | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, that's strange. do all messages in a channel have a unique timestamp? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, lmao. They are the primary key of messages, which is an Interesting design decision on the part of Slack, but I guess, there are many of those. |
||
-- ^ \"Timestamp of the message to be updated.\" | ||
, updateReqAsUser :: Maybe Bool | ||
-- ^ \"Pass true to update the message as the authed user. Bot users in this context are considered authed users.\" | ||
, updateReqAttachments :: Maybe Text | ||
-- ^ \"A JSON-based array of structured attachments, presented as a URL-encoded string. This field is required when not presenting text. If you don't include this field, the message's previous attachments will be retained. To remove previous attachments, include an empty array for this field.\" | ||
, updateReqLinkNames :: Maybe Bool | ||
, updateReqMetadata :: Maybe Text | ||
, updateReqParse :: Maybe Text | ||
, updateReqReplyBroadcast :: Maybe Bool | ||
-- ^ \"Broadcast an existing thread reply to make it visible to everyone in the channel or conversation.\" | ||
, updateReqText :: Maybe Text | ||
-- ^ \"New text for the message, using the default formatting rules. It's not required when presenting blocks or attachments.\" | ||
} | ||
deriving stock (Eq, Generic, Show) | ||
|
||
instance ToForm UpdateReq where | ||
toForm = genericToForm (formOpts "updateReq") | ||
|
||
mkUpdateReq :: ConversationId -> Text -> UpdateReq | ||
mkUpdateReq channel ts = | ||
UpdateReq | ||
{ updateReqChannel = channel | ||
, updateReqTs = ts | ||
, updateReqAsUser = Nothing | ||
, updateReqAttachments = Nothing | ||
, updateReqLinkNames = Nothing | ||
, updateReqMetadata = Nothing | ||
, updateReqParse = Nothing | ||
, updateReqReplyBroadcast = Nothing | ||
, updateReqText = Nothing | ||
} | ||
|
||
data UpdateRsp = UpdateRsp | ||
{ updateRspChannel :: ConversationId | ||
, updateRspTs :: Text | ||
, updateRspText :: Text | ||
-- FIXME(jadel): this does look suspiciously like the same schema as | ||
-- MessageEvent based on the example I received, but Slack hasn't documented | ||
-- what it actually is, so let's not try to parse it for now. | ||
-- , message :: MessageEvent | ||
} | ||
deriving stock (Eq, Generic, Show) | ||
|
||
$(deriveFromJSON (jsonOpts "updateRsp") ''UpdateRsp) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Web.Slack.ChatSpec (spec) where | ||
|
||
import JSONGolden | ||
import TestImport | ||
import Web.Slack.Chat (UpdateRsp) | ||
|
||
spec :: Spec | ||
spec = describe "Chat methods" do | ||
describe "chat.update" do | ||
describe "Response FromJSON" do | ||
mapM_ (oneGoldenTest @UpdateRsp) ["sample", "actual"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{ | ||
"token": "aaaa", | ||
"team_id": "T043DB835ML", | ||
"api_app_id": "A0442TUPHGR", | ||
"event": { | ||
"type": "message", | ||
"text": "", | ||
"user": "U043H11ES4V", | ||
"ts": "1668537593.598469", | ||
"team": "T043DB835ML", | ||
"attachments": [ | ||
{ | ||
"from_url": "https://jadeapptesting.slack.com/archives/C043KSKGJUB/p1665615886364019", | ||
"ts": "1665615886.364019", | ||
"author_id": "U043H11ES4V", | ||
"channel_id": "C043KSKGJUB", | ||
"channel_team": "T043DB835ML", | ||
"channel_name": "testing-slack-app", | ||
"is_msg_unfurl": true, | ||
"message_blocks": [ | ||
{ | ||
"team": "T043DB835ML", | ||
"channel": "C043KSKGJUB", | ||
"ts": "1665615886.364019", | ||
"message": { | ||
"blocks": [ | ||
{ | ||
"type": "rich_text", | ||
"block_id": "TNHa4", | ||
"elements": [ | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [ | ||
{ | ||
"type": "text", | ||
"text": "blahblahblahblahblah" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
], | ||
"color": "D0D0D0", | ||
"is_share": true, | ||
"fallback": "[October 12th, 2022 4:04 PM] jadel: blahblahblahblahblah", | ||
"text": "blahblahblahblahblah", | ||
"author_name": "jadel", | ||
"author_link": "https://jadeapptesting.slack.com/team/U043H11ES4V", | ||
"author_icon": "https://secure.gravatar.com/avatar/dcd5bc53dcfaca62ddc3f5726d07ba13.jpg?s=48&d=https%3A%2F%2Fa.slack-edge.com%2Fdf10d%2Fimg%2Favatars%2Fava_0019-48.png", | ||
"author_subname": "jadel", | ||
"mrkdwn_in": [ | ||
"text" | ||
], | ||
"footer": "Posted in #testing-slack-app" | ||
} | ||
], | ||
"channel": "C043YJGBY49", | ||
"event_ts": "1668537593.598469", | ||
"channel_type": "channel" | ||
}, | ||
"type": "event_callback", | ||
"event_id": "Ev04BEN3QMSM", | ||
"event_time": 1668537593, | ||
"authorizations": [ | ||
{ | ||
"enterprise_id": null, | ||
"team_id": "T043DB835ML", | ||
"user_id": "U0442US8QGH", | ||
"is_bot": true, | ||
"is_enterprise_install": false | ||
} | ||
], | ||
"is_ext_shared_channel": false, | ||
"event_context": "aaaa" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
UpdateRsp | ||
{ updateRspChannel = ConversationId | ||
{ unConversationId = "D0442US94JD" } | ||
, updateRspTs = "1668717810.728689" | ||
, updateRspText = "blahblahblah" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"ok": true, | ||
"channel": "D0442US94JD", | ||
"ts": "1668717810.728689", | ||
"text": "blahblahblah", | ||
"message": { | ||
"bot_id": "B0439P161B9", | ||
"type": "message", | ||
"text": "blahblahblah", | ||
"user": "U0442US8QGH", | ||
"app_id": "A0442TUPHGR", | ||
"blocks": [ | ||
{ | ||
"type": "rich_text", | ||
"block_id": "j1Bvn", | ||
"elements": [ | ||
{ | ||
"type": "rich_text_section", | ||
"elements": [ | ||
{ | ||
"type": "text", | ||
"text": "blahblahblah" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"team": "T043DB835ML", | ||
"bot_profile": { | ||
"id": "B0439P161B9", | ||
"app_id": "A0442TUPHGR", | ||
"name": "Slacklinker dev", | ||
"icons": { | ||
"image_36": "https://a.slack-edge.com/80588/img/plugins/app/bot_36.png", | ||
"image_48": "https://a.slack-edge.com/80588/img/plugins/app/bot_48.png", | ||
"image_72": "https://a.slack-edge.com/80588/img/plugins/app/service_72.png" | ||
}, | ||
"deleted": false, | ||
"updated": 1663960005, | ||
"team_id": "T043DB835ML" | ||
}, | ||
"edited": { | ||
"user": "B0439P161B9", | ||
"ts": "1668721589.000000" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
UpdateRsp | ||
{ updateRspChannel = ConversationId | ||
{ unConversationId = "C024BE91L" } | ||
, updateRspTs = "1401383885.000061" | ||
, updateRspText = "Updated text you carefully authored" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"ok": true, | ||
"channel": "C024BE91L", | ||
"ts": "1401383885.000061", | ||
"text": "Updated text you carefully authored", | ||
"message": { | ||
"text": "Updated text you carefully authored", | ||
"user": "U34567890" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like I've asked this before about this file, but where are all these "underscored" functions defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slack-web/src/Web/Slack.hs
Lines 296 to 304 in ffeccec