為解一個 line API 傳送文字的限制,在官網上看到的資訊,
順便玩玩這個 emoticons 功能.
官網上的 URL 為
https://devdocs.line.me/en/#send-message-object
Send message object
JSON object which contains the contents of the message you send.
Text
Image
Video
Audio
Location
Sticker
Imagemap
Template
Text
Text example
{
"type": "text",
"text": "Hello, world"
}
Field
Type
Required
Description
type
String
Yes
text
text
String
Yes
Message text
Max: 2000 characters
Text example with emoticon
{
"type": "text",
"text": "Hello, world "
}
You can include emoticons in your message text. Because emoticons are
a part of Unicode, they must be converted from their character codes.
Note that the character code, 0x1000B2, is used in the example on the
right. Although the emoticon does not show up correctly in the browser,
it will show up in LINE.
For a list of emoticons that can be sent with the Messaging API,
see emoticon list.
https://devdocs.line.me/files/emoticon.pdf
perl 的用法可參考
http://www.drdobbs.com/web-development/unicode-in-perl/184416148
及
https://github.com/patch-orphan/text-emoticon-unicode-pm5
加上
https://github.com/line/line-bot-sdk-perl
所以可以加以變化成 如下的程式.....
[root@CentOS73 bin]# cat Send-Line-Message.pl
#!/usr/local/perl-5.26/bin/perl
use LINE::Bot::API;
use LINE::Bot::API::Builder::SendMessage;
$bot = LINE::Bot::API->new(
channel_secret => 'xxxxxxxxxxxxxxxxxxxxxxxxx',
channel_access_token => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=',
);
use Text::Emoticon;
$emoticon = Text::Emoticon->new('Unicode');
$msg = $emoticon->filter('Howdy :) :( ');
$ToLineUid = 'Uxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$messages = LINE::Bot::API::Builder::SendMessage->new;
$messages->add_text( text => "Example push text \r\n $msg \x{1F480}" );
$bot->push_message($ToLineUid, $messages->build);
[root@CentOS73 bin]#
Demo
其它參考資訊
http://unicode.org/emoji/charts/full-emoji-list.html
http://xrcd2.blogspot.tw/2016/12/perl-line-api.html