diff --git a/lib/wechat/message.rb b/lib/wechat/message.rb index e6b80b56..79726113 100644 --- a/lib/wechat/message.rb +++ b/lib/wechat/message.rb @@ -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) @@ -206,6 +210,7 @@ def to_xml 'TextCard' => 'textcard', 'Markdown' => 'markdown', 'ToUserName' => 'touser', + 'ToPartyName' => 'toparty', 'ToWxName' => 'towxname', 'MediaId' => 'media_id', 'MpNews' => 'mpnews', @@ -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 diff --git a/spec/lib/wechat/message_spec.rb b/spec/lib/wechat/message_spec.rb index fbefde17..be6464d4 100644 --- a/spec/lib/wechat/message_spec.rb +++ b/spec/lib/wechat/message_spec.rb @@ -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