Skip to content

Commit

Permalink
Merge pull request #249 from rallets-network/master
Browse files Browse the repository at this point in the history
let Wechat::Message support textcard, test included
  • Loading branch information
Eric-Guo authored Jan 18, 2019
2 parents 6cb727c + cfbc383 commit ed1b093
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/wechat/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ def text(content)
update(MsgType: 'text', Content: content)
end

def textcard(title, description, url, btntxt)
update(MsgType: 'textcard', TextCard: {
title: title,
description: description,
url: url,
btntxt: btntxt
})
end

def transfer_customer_service(kf_account = nil)
if kf_account
update(MsgType: 'transfer_customer_service', TransInfo: { KfAccount: kf_account })
Expand Down Expand Up @@ -187,6 +196,7 @@ def to_xml
end

TO_JSON_KEY_MAP = {
'TextCard' => 'textcard',
'ToUserName' => 'touser',
'ToWxName' => 'towxname',
'MediaId' => 'media_id',
Expand All @@ -198,7 +208,7 @@ def to_xml
'ShowCoverPic' => 'show_cover_pic'
}.freeze

TO_JSON_ALLOWED = %w[touser msgtype content image voice video file
TO_JSON_ALLOWED = %w[touser msgtype content image voice video file textcard
music news articles template agentid filter
send_ignore_reprint mpnews towxname].freeze

Expand Down
8 changes: 8 additions & 0 deletions spec/lib/wechat/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@
end
end

describe '#textcard' do
specify 'will update MsgType and TextCard field and return self' do
expect(message.textcard('title', 'content', 'URL', '更多')).to eq(message)
expect(message[:MsgType]).to eq 'textcard'
expect(message[:TextCard]).to eq ({btntxt: '更多', description: 'content', title: 'title', url: 'URL'})
end
end

describe '#transfer_customer_service' do
specify 'will update MsgType and return self' do
expect(message.transfer_customer_service).to eq(message)
Expand Down

0 comments on commit ed1b093

Please sign in to comment.