@@ -33,26 +33,45 @@ module Office365::ChannelMessages
3333 end
3434
3535 def list_channel_messages (response : HTTP ::Client ::Response )
36- ChatMessageList .from_json(response.body)
36+ if response.success?
37+ ChatMessageList .from_json(response.body)
38+ else
39+ raise " error listing channel messages #{ response.status } (#{ response.status_code } \n #{ response.body } "
40+ end
3741 end
3842
3943 def get_channel_message (team_id : String , channel_id : String , message_id : String )
4044 request = graph_http_request(request_method: " GET" , path: " /v1.0/teams/#{ team_id } /channels/#{ channel_id } /messages/#{ message_id } " )
4145 response = graph_request(request)
42- ChatMessage .from_json(response.body)
46+ if response.success?
47+ ChatMessage .from_json(response.body)
48+ else
49+ raise " error getting channel message #{ response.status } (#{ response.status_code } \n #{ response.body } "
50+ end
4351 end
4452
4553 def send_channel_message (team_id : String , channel_id : String , message : String | IO )
4654 body = message.is_a?(IO ) ? message.gets_to_end : message
4755 chat = ChatMessage .new(body: body)
4856 request = graph_http_request(request_method: " POST" , path: " /v1.0/teams/#{ team_id } /channels/#{ channel_id } /messages" , data: chat.to_json)
49- graph_request(request)
57+ response = graph_request(request)
58+
59+ if response.success?
60+ ChatMessage .from_json(response.body)
61+ else
62+ raise " error sending channel message #{ response.status } (#{ response.status_code } \n #{ response.body } "
63+ end
5064 end
5165
5266 def send_channel_message (team_id : String , channel_id : String , message : String | IO , content_type : String )
5367 body = message.is_a?(IO ) ? message.gets_to_end : message
5468 chat = ChatMessage .new(content: body, content_type: content_type)
5569 request = graph_http_request(request_method: " POST" , path: " /v1.0/teams/#{ team_id } /channels/#{ channel_id } /messages" , data: chat.to_json)
56- graph_request(request)
70+ response = graph_request(request)
71+ if response.success?
72+ ChatMessage .from_json(response.body)
73+ else
74+ raise " error sending channel message #{ response.status } (#{ response.status_code } \n #{ response.body } "
75+ end
5776 end
5877end
0 commit comments