Skip to content

Commit

Permalink
New translatecontent support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Guo committed Nov 15, 2019
1 parent 909b61f commit 12fbdbd
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* ADD: Wechat::MpApi.subscribe_message_send. by @paicha #271
* FIX: FrozenError: can't modify frozen String. by @paicha #272
* New translatecontent support.

## v0.11.6 (released at 09/02/2019)

Expand Down
1 change: 1 addition & 0 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ Wechat Public Account commands:
wechat tag_update [TAG_ID, TAGNAME] # 更新标签名字
wechat tags # 获取所有标签
wechat template_message [OPENID, TEMPLATE_YAML_PATH] # 模板消息接口
wechat translatecontent [CONTENT] # AI开放接口-微信翻译
wechat user [OPEN_ID] # 获取用户基本信息
wechat user_batchget [OPEN_ID_LIST] # 批量获取用户基本信息
wechat user_change_group [OPEN_ID, TO_GROUP_ID] # 移动用户分组
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ Wechat Public Account commands:
wechat tag_update [TAG_ID, TAGNAME] # 更新标签名字
wechat tags # 获取所有标签
wechat template_message [OPENID, TEMPLATE_YAML_PATH] # 模板消息接口
wechat translatecontent [CONTENT] # AI开放接口-微信翻译
wechat user [OPEN_ID] # 获取用户基本信息
wechat user_batchget [OPEN_ID_LIST] # 批量获取用户基本信息
wechat user_change_group [OPEN_ID, TO_GROUP_ID] # 移动用户分组
Expand Down
5 changes: 5 additions & 0 deletions bin/wechat
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ class App < Thor
def queryrecoresultfortext(voice_id)
puts wechat_api.queryrecoresultfortext(voice_id)
end

desc 'translatecontent [CONTENT]', 'AI开放接口-微信翻译'
def translatecontent(content)
puts wechat_api.translatecontent(content)
end
end

desc 'user [OPEN_ID]', '获取用户基本信息'
Expand Down
4 changes: 4 additions & 0 deletions lib/wechat/concern/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ def queryrecoresultfortext(voice_id, lang = 'zh_CN')
post 'media/voice/queryrecoresultfortext', nil, params: { voice_id: voice_id, lang: lang }
end

def translatecontent(from_content, lfrom = 'zh_CN', lto = 'en_US')
post 'media/voice/translatecontent', from_content, params: { lfrom: lfrom, lto: lto }
end

def web_access_token(code)
params = {
appid: access_token.appid,
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/wechat/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -824,4 +824,16 @@
expect(subject.queryrecoresultfortext('xxxxxx')).to eq response_result
end
end

describe '#translatecontent' do
specify 'will post media/voice/translatecontent with access_token, lfrom and lto as params and content in body' do
response_result = { from_content: "xxxxxxxx", to_content: "xxxxxxxx" }

expect(subject.client).to receive(:post)
.with('media/voice/translatecontent', 'xxxxxxxx',
params: { access_token: 'access_token', lfrom: 'zh_CN', lto: 'en_US' })
.and_return(response_result)
expect(subject.translatecontent('xxxxxxxx')).to eq response_result
end
end
end

0 comments on commit 12fbdbd

Please sign in to comment.