Skip to content

Commit

Permalink
添加导入聊天记录的API接口
Browse files Browse the repository at this point in the history
  • Loading branch information
JiangYongKang committed Sep 21, 2020
1 parent d575039 commit 960fcfa
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
tim_sdk (0.1.2)
tim_sdk (0.1.4)

GEM
remote: https://rubygems.org/
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
- [x] 失效帐号登录态
- [x] 查询帐号在线状态

- [x] 单聊消息
- [x] 导入单聊消息

- [x] 资料管理
- [x] 设置资料
- [x] 拉取资料
Expand Down Expand Up @@ -93,6 +96,26 @@ TimSdk::Api.invoke_query_state(%w[foo bar])
#=> {:ActionStatus=>"OK", :ErrorInfo=>"", :ErrorCode=>0, :QueryResult=>[{:To_Account=>"bar", :State=>"Offline", :Status=>"Offline"}, {:To_Account=>"foo", :State=>"Offline", :Status=>"Offline"}]}
```

导入聊天消息
```ruby
TimSdk::Api.invoke_import_msg(
'foo',
'bar',
4122534,
1556178721,
2,
[
{
"msg_type": "TIMTextElem",
"msg_content": {
"text": "Hello World"
}
}
]
)
#=> {:ActionStatus=>"OK", :ErrorInfo=>"", :ErrorCode=>0}
```

设置资料
```ruby
TimSdk::Api.invoke_portrait_set('foo', [
Expand Down
16 changes: 16 additions & 0 deletions lib/tim_sdk/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ def self.invoke_query_state(accounts, is_need_detail = 0)
JSON.parse(response.body, symbolize_names: true) if response.success?
end

# 导入单聊消息
def self.invoke_import_msg(from_account, to_account, msg_random, msg_timestamp, sync_from_old_system, msg_body)
response = connection.post('/v4/openim/importmsg') do |request|
request.body = {
:SyncFromOldSystem => sync_from_old_system,
:From_Account => from_account.to_s,
:To_Account => to_account.to_s,
:MsgRandom => msg_random.to_i,
:MsgTimeStamp => msg_timestamp.to_i,
:MsgBody => msg_body
}.to_json
end
raise TimServerError, "Response Status: #{response.status}" unless response.success?
JSON.parse(response.body, symbolize_names: true) if response.success?
end

# 设置资料
def self.invoke_portrait_set(account, items)
response = connection.post('/v4/profile/portrait_set') do |request|
Expand Down
2 changes: 1 addition & 1 deletion lib/tim_sdk/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TimSdk
VERSION = '0.1.3'
VERSION = '0.1.4'
end
20 changes: 20 additions & 0 deletions spec/tim_sdk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@
expect(response[:ErrorCode]).to eq(0)
end

it 'should be import message successfully' do
response = TimSdk::Api.invoke_import_msg(
'foo',
'bar',
4122534,
1556178721,
2,
[
{
"msg_type": "TIMTextElem",
"msg_content": {
"text": "Hello World"
}
}
]
)
expect(response[:ActionStatus]).to eq('OK')
expect(response[:ErrorCode]).to eq(0)
end

it 'should be set account portrait successfully' do
response = TimSdk::Api.invoke_portrait_set('foo', [
{ tag: 'Tag_Profile_IM_Nick', value: 'vincent', },
Expand Down

0 comments on commit 960fcfa

Please sign in to comment.