Skip to content

Commit

Permalink
Merge pull request #256 from rallets-network/master
Browse files Browse the repository at this point in the history
allow a message to be sent to a party(department)
  • Loading branch information
Eric-Guo authored Mar 14, 2019
2 parents 0e48f15 + f235b11 commit 2adcd4b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/wechat/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def to(to_users = '', towxname: nil, send_ignore_reprint: 0)
end
end

def to_party(party)
new(ToPartyName: party, CreateTime: Time.now.to_i)
end

def to_mass(tag_id: nil, send_ignore_reprint: 0)
if tag_id
new(filter: { is_to_all: false, tag_id: tag_id }, send_ignore_reprint: send_ignore_reprint)
Expand Down Expand Up @@ -206,6 +210,7 @@ def to_xml
'TextCard' => 'textcard',
'Markdown' => 'markdown',
'ToUserName' => 'touser',
'ToPartyName' => 'toparty',
'ToWxName' => 'towxname',
'MediaId' => 'media_id',
'MpNews' => 'mpnews',
Expand All @@ -216,7 +221,7 @@ def to_xml
'ShowCoverPic' => 'show_cover_pic'
}.freeze

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

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

describe 'to_party' do
let(:message) { Wechat::Message.from_hash(text_request) }
specify 'will create a message sent to a party' do
reply = Wechat::Message.to_party(2)
expect(reply).to be_a(Wechat::Message)
expect(reply.message_hash).to include(ToPartyName: 2)
expect(reply.message_hash[:CreateTime]).to be_a(Integer)
end
end

describe 'to_mass' do
let(:message) { Wechat::Message.from_hash(text_request) }
specify 'will create base message' do
Expand Down

0 comments on commit 2adcd4b

Please sign in to comment.