#mobile-app-discussions

Issues with update_presence Command & contact_last_seen_at API.

TLDR Mr.Bean struggles with "contact_last_seen_at" being 0 despite update_presence command. sojan_official explains it's updated based on user interactions with the chatwoot widget, not via direct APIs.

Powered by Struct AI
Aug 18, 2022 (16 months ago)
Mr.Bean
Photo of none
Mr.Bean
05:23 AM
Hi Sojan,
I was able find to the api but still contact_last_seen_at is 0
{ "account_id": 1,
"additional_attributes": {},
"agent_last_seen_at": 1660779366,
"assignee_last_seen_at": 1660779324,
"can_reply": true,
"contact_last_seen_at": 0,
"custom_attributes": {},
"inbox_id": 1,
"labels": [],
"muted": false,
"snoozed_until": null,
"status": "open",
"timestamp": 1660779324,
"unread_count": 0
}
Also when we update_presence using

{"command":"message","identifier":"{\"channel\":\"RoomChannel\",\"pubsub_token\":\"pubsub_token\"}","data":"{\"action\":\"update_presence\"}"}

we always get this error block invoke

chweb01.log:E, [2022-08-17T23:35:45.102798 #15] ERROR -- : Could not execute command from ({"command"=>"message", "identifier"=>"{\"channel\":\"RoomChannel\",\"pubsub_token\":\"pubsub\"}", "data"=>"{\"action\":\"update_presence\"}"}) [RuntimeError - Unable to find subscription with identifier: {"channel":"RoomChannel","pubsub_token":"pubsub"}]: /gems/ruby/3.0.0/gems/actioncable-6.1.5.1/lib/action_cable/connection/subscriptions.rb:75:in find' | /gems/ruby/3.0.0/gems/actioncable-6.1.5.1/lib/action_cable/connection/subscriptions.rb:56:in perform_action' | /gems/ruby/3.0.0/gems/actioncable-6.1.5.1/lib/action_cable/connection/subscriptions.rb:19:in execute_command' | /gems/ruby/3.0.0/gems/actioncable-6.1.5.1/lib/action_cable/connection/base.rb:89:in dispatch_websocket_message' | /gems/ruby/3.0.0/gems/actioncable-6.1.5.1/lib/action_cable/server/worker.rb:60:in `block in invoke'
sojan_official
Photo of md5-788237a2af5ff191b07ee9f215706ead
sojan_official
10:32 AM
you need to establish a subscription before you can send presence updates

ref: https://www.chatwoot.com/docs/product/others/websocket-events#connect-to-chatwoot-websocket


-----

also looking into the code it seems like we dont have direct apis to update contact_last_seen_at . at the moment it is only updated based on a users interaction over the chatwoot chat widget. i have logged https://github.com/chatwoot/chatwoot/issues/5299 to track this
Mr.Bean
Photo of none
Mr.Bean
03:29 PM
I did send the subscribe message before sending the presence message. I tried it again today and still getting the Could not execute command in chatwoot web logs as shown below.

PLease see attached is the sequence of message send and received below.
03:31
Mr.Bean
03:31 PM
Send intial subscribe
{"command":"subscribe","identifier":"{\"channel\":\"RoomChannel\",\"pubsub_token\":\"4hNweRAeG8UuDV5jLEVYY8sC\",\"account_id\":1}"}

Response message with confirmation of subscription
{
"identifier": "{\"channel\":\"RoomChannel\",\"pubsub_token\":\"4hNweRAeG8UuDV5jLEVYY8sC\",\"account_id\":1}",
"type": "confirm_subscription"
}

Response message with presence update
{
"identifier": "{\"channel\":\"RoomChannel\",\"pubsub_token\":\"4hNweRAeG8UuDV5jLEVYY8sC\",\"account_id\":1}",
"message": {
"event": "presence.update",
"data": {
"account_id": 1,
"users": {
"1": "online"
}
}
}
}

Send presence update
{"command":"message","identifier":"{\"channel\":\"RoomChannel\",\"pubsub_token\":\"4hNweRAeG8UuDV5jLEVYY8sC\"}","data":"{\"action\":\"update_presence\"}"}
03:32
Mr.Bean
03:32 PM
Response of send presence update

Error in chatwoot weblogs
[2022-08-18T14:04:37.730115 #15] ERROR -- : Could not execute command from ({"command"=>"message", "identifier"=>"{\"channel\":\"RoomChannel\",\"pubsub_token\":\"4hNweRAeG8UuDV5jLEVYY8sC\"}", "data"=>"{\"action\":\"update_presence\"}"}) [RuntimeError - Unable to find subscription with identifier: {"channel":"RoomChannel","pubsub_token":"4hNweRAeG8UuDV5jLEVYY8sC"}]: /gems/ruby/3.0.0/gems/actioncable-6.1.5.1/lib/action_cable/connection/subscriptions.rb:75:in find' | /gems/ruby/3.0.0/gems/actioncable-6.1.5.1/lib/action_cable/connection/subscriptions.rb:56:in perform_action' | /gems/ruby/3.0.0/gems/actioncable-6.1.5.1/lib/action_cable/connection/subscriptions.rb:19:in execute_command' | /gems/ruby/3.0.0/gems/actioncable-6.1.5.1/lib/action_cable/connection/base.rb:89:in dispatch_websocket_message' | /gems/ruby/3.0.0/gems/actioncable-6.1.5.1/lib/action_cable/server/worker.rb:60:in `block in invoke'
03:33
Mr.Bean
03:33 PM
#####################
03:36
Mr.Bean
03:36 PM
Response after calling conversation api. Please see contact_last_seen_at is still 0.
{{host}}/{{api_version}}/accounts/{{account_id}}/contacts/{{contact_id}}/conversations
{
"payload": [
{
"meta": {
"sender": {
"additional_attributes": {},
"availability_status": "offline",
"email": "[email protected]",
"id": 1,
"name": "First Last",
"phone_number": null,
"identifier": null,
"thumbnail": "null",
"custom_attributes": {},
"last_activity_at": 1660779317
},
"channel": "Channel::Api",
"assignee": {
"id": 1,
"account_id": 1,
"availability_status": "offline",
"auto_offline": true,
"confirmed": true,
"email": "[email protected]",
"available_name": "First Last",
"name": "First Last",
"role": "administrator",
"thumbnail": "null"
},
"hmac_verified": false
},
"id": 1,
03:36
Mr.Bean
03:36 PM
"messages": [
{
"id": 350,
"content": "ok",
"account_id": 1,
"inbox_id": 1,
"conversation_id": 1,
"message_type": 1,
"created_at": 1660779324,
"updated_at": "2022-08-17T23:35:24.649Z",
"private": false,
"status": "sent",
"source_id": null,
"content_type": "text",
"content_attributes": {},
"sender_type": "User",
"sender_id": 1,
"external_source_ids": {},
"additional_attributes": {},
"conversation": {
"assignee_id": 1
},
"sender": {
"id": 1,
"name": "First Last",
"available_name": "First Last",
"avatar_url": "null",
"type": "user",
"availability_status": "offline",
"thumbnail": "null"
}
}
],
"account_id": 1,
"additional_attributes": {},
"agent_last_seen_at": 1660831522,
"assignee_last_seen_at": 1660831522,
"can_reply": true,
"contact_last_seen_at": 0,
"custom_attributes": {},
"inbox_id": 1,
"labels": [],
"muted": false,
"snoozed_until": null,
"status": "open",
"timestamp": 1660779324,
"unread_count": 0
}
]
}

Chatwoot

Chatwoot | Knowledge Base powered by Struct.AI

Indexed 2214 threads (46% resolved)

Generate Knowledge