Hello there.
We should have a possibility to send a reply to the previously sent message, wich seems to be impossible as for now, due to the absence of response itself. There's a ts field in Slack's response, which is effectively a message's ID.
You may wonder:
Q: Why not to return ResponseInterface straight away?
A: Well, that's a low-level transport detail, which should not take place in our service layer. We should not expose those http-related details to the outer world.
Q: Why not to return a plain array so to avoid an extra dependency?
A: Arrays don't have contracts, it's better not to pass them all around the system. Also json_decode can return false.
Q: Why not to use typed ValueObject?
A: API may change. They can break/add things. Mess allows us to tolerate Slack's changes. We should only fail if we can't get the field we really need (For example now we only need ts field, which is unlikely subject to change. Others may need ok or some other extra fields).
With all that being said, let's go down to the business:
It's now possible to get sent message's ID - $client->send($message)['ts']->getString().
It's type safe, with no PHP's magic type conversion involved.
If you're ok with the solution - I'll fix Travis issues
An example response:
{
"ok": true,
"channel": "C1H9RESGL",
"ts": "1503435956.000247",
"message": {
"text": "Here's a message for you",
"username": "ecto1",
"bot_id": "B19LU7CSY",
"attachments": [
{
"text": "This is an attachment",
"id": 1,
"fallback": "This is an attachment's fallback"
}
],
"type": "message",
"subtype": "bot_message",
"ts": "1503435956.000247"
}
}
Hello there. We should have a possibility to send a reply to the previously sent message, wich seems to be impossible as for now, due to the absence of response itself. There's a
ts
field in Slack's response, which is effectively a message's ID.You may wonder: Q: Why not to return
ResponseInterface
straight away? A: Well, that's a low-level transport detail, which should not take place in our service layer. We should not expose those http-related details to the outer world.Q: Why not to return a plain array so to avoid an extra dependency? A: Arrays don't have contracts, it's better not to pass them all around the system. Also
json_decode
can return false.Q: Why not to use typed
ValueObject
? A: API may change. They can break/add things.Mess
allows us to tolerate Slack's changes. We should only fail if we can't get the field we really need (For example now we only needts
field, which is unlikely subject to change. Others may needok
or some other extra fields).With all that being said, let's go down to the business: It's now possible to get sent message's ID -
$client->send($message)['ts']->getString()
. It's type safe, with no PHP's magic type conversion involved.If you're ok with the solution - I'll fix Travis issues
An example response: