Commit e710134c0b523421e7efa685680f0b305fe88c5c

Authored by Matti Virkkunen
1 parent afd428c0

Documented sending image messages.

Showing 1 changed file with 74 additions and 1 deletions
line-protocol.md
... ... @@ -321,17 +321,26 @@ Messages can contain extra attributes in the contentMetadata map. One globally u
321 321 "BOT_CHECK" which is included with a value of "1" for automatic messages I've received from
322 322 "official accounts" - this could be an auto-reply indicator.
323 323  
324   -### NONE (0) (actually text)
  324 +### NONE (0)
325 325  
326 326 The first contentType is called NONE internally but is actually text. It's the simplest content
327 327 type. The text field contains the message content encoded in UTF-8.
328 328  
329 329 The only thing to watch out for is emoji which are sent as Unicode private use area codepoints.
330 330  
  331 +Example:
  332 +
  333 + client.sendMessage(0, line.Message(
  334 + to="u0123456789abcdef0123456789abcdef",
  335 + contentType=line.ContentType.NONE,
  336 + text="Hello, world!"))
  337 +
331 338 TODO: make a list of emoji
332 339  
333 340 ### IMAGE (1)
334 341  
  342 +#### Receiving
  343 +
335 344 Image message content can be delivered in one of two ways.
336 345  
337 346 For normal image messages, a preview image is included as a plain JPEG in the contentPreview field.
... ... @@ -354,6 +363,70 @@ As an example of a publicly available image message, have a Pikachu:
354 363  
355 364 http://dl-obs.official.line.naver.jp/r/talk/o/u3ae3691f73c7a396fb6e5243a8718915-1379585871
356 365  
  366 +#### Sending
  367 +
  368 +Sending an image message is done in two steps. First a Thrift sendMessage call is used to obtain a
  369 +message ID, and then the image data is uploaded to the Object Storage Server with a separate HTTP
  370 +upload request.
  371 +
  372 +The message will not be delivered to the recipient until the HTTP upload is complete. The official
  373 +client displays messages in the order of the sendMessage calls, even if the image data is uploaded
  374 +much later. It might be possible to have fun by "reserving" a spot for an image message in a
  375 +conversation and then filling it in later. It's unknown if there's an internal timeout for uploading
  376 +the image data.
  377 +
  378 +In order to send an image message, first send a message normally with contentType=1 (IMAGE) and make
  379 +note of the returned message ID. The official client also puts "1000000000" in the text field. The
  380 +meaning of this is unknown and it's not required.
  381 +
  382 +The upload HTTP request is a multipart/form-data ("file upload") POST request to the URL:
  383 +
  384 +https://os.line.naver.jp/talk/m/upload.nhn
  385 +
  386 +The request uses the usual X-Line-Application and the X-Line-Access headers for authentication.
  387 +There are two fields in the multipart request. The first field is called "params" and the content is
  388 +a JSON object containing among other things the message ID. There is on Content-Type header.
  389 +
  390 +{"name":"1.jpg","oid":"1234567890123","size":28878,"type":"image","ver":"1.0"}
  391 +
  392 +The name field does not seem to be used for anything. oid should be set to the message ID obtained
  393 +earlier. size should be set to the size of the image file to upload.
  394 +
  395 +The second field is called "file" with a filename argument, has a Content-Type header, and contains
  396 +the image data itself. The filename and Content-Type headers seem to be ignored and the image format
  397 +is automatically detected. At least JPEG and PNG data is supported for uploading, but everything is
  398 +converted to JPEG by the server.
  399 +
  400 +Example sendMessage call:
  401 +
  402 + # First send the message by using sendMessage
  403 + result = client.sendMessage(0, line.Message(
  404 + to="u0123456789abcdef0123456789abcdef",
  405 + contentType=line.ContentType.IMAGE))
  406 +
  407 + # Store the ID
  408 + oid = result.id
  409 +
  410 +Example HTTP upload:
  411 +
  412 + POST /talk/m/upload.nhn HTTP/1.1
  413 + Content-Length: 29223
  414 + Content-Type: multipart/form-data; boundary=--boundary-CU3U3JIM7B17R0C4SIWX1NS7I1G0LV6BF76GPTNN
  415 + Host: obs-de.line-apps.com:443
  416 + X-Line-Access: D82j....=
  417 + X-Line-Application: DESKTOPWIN\t3.6.0.32\tWINDOWS 5.0.2195-XP-x64
  418 +
  419 + --boundary-CU3U3JIM7B17R0C4SIWX1NS7I1G0LV6BF76GPTNN
  420 + Content-Disposition: form-data; name="params"
  421 +
  422 + {"name":"1.jpg","oid":"1234567890123","size":28878,"type":"image","ver":"1.0"}
  423 + --boundary-CU3U3JIM7B17R0C4SIWX1NS7I1G0LV6BF76GPTNN
  424 + Content-Disposition: form-data; name="file"; filename="1.jpg"
  425 + Content-Type: image/jpeg
  426 +
  427 + ...image data...
  428 + --boundary-CU3U3JIM7B17R0C4SIWX1NS7I1G0LV6BF76GPTNN--
  429 +
357 430 ### STICKER (7)
358 431  
359 432 Sticker messages are simply a reference to a separately hosted image file. The information required
... ...