psnawp_api.models.group.group module#

Provides Group class for creating message groups and interacting with message groups.

class Group(authenticator: Authenticator, group_id: str)[source]#

Bases: object

The Group class manages PSN group endpoints related to messages (Group and Direct Messages).

Variables:
  • authenticator (Authenticator) – An instance of Authenticator used to authenticate and make HTTPS requests.

  • group_id (str) – Unique ID representing a specific PSN group or direct message thread.

Note

This class is intended to be used via PSNAWP. See psnawp_api.psnawp.PSNAWP.group() or psnawp_api.client.Client.get_groups()

Constructor of Group.

Parameters:
  • authenticator – The Authenticator instance used for making authenticated requests to the API.

  • group_id – The Group ID of a group.

Raises:

The canonical way to create instance of this class is to the class method Group.create_from_group_id() and Group.create_from_users().

__init__(authenticator: Authenticator, group_id: str) None[source]#

Constructor of Group.

Parameters:
  • authenticator – The Authenticator instance used for making authenticated requests to the API.

  • group_id – The Group ID of a group.

Raises:

The canonical way to create instance of this class is to the class method Group.create_from_group_id() and Group.create_from_users().

change_name(group_name: str) None[source]#

Changes the group name to one specified in arguments.

Parameters:

group_name – The name of the group that will be set.

Returns:

None

Raises:

PSNAWPBadRequestError – If you are not part of group or the group is a DM.

Note

You cannot change the name of DM groups. i.e. Groups with only two people (including you).

classmethod create_from_group_id(authenticator: Authenticator, group_id: str) Self[source]#

Create Group instance with group id.

Parameters:
  • authenticator – The Authenticator instance used for making authenticated requests to the API.

  • group_id – The Group ID of a group.

Returns:

Instance of Group

classmethod create_from_users(authenticator: Authenticator, users: Iterable[User]) Self[source]#

Creates a new message Group from the provide list of Users.

Raises:

PSNAWPForbiddenError – If you are sending message a user who has blocked you.

get_conversation(limit: int = 20) dict[str, Any][source]#

Gets the conversations in a group.

Parameters:

limit – The number of conversations to receive.

Returns:

A dict containing info similar to what is shown below:

{
    "messages": [
        {
            "messageUid": "1#425961448584099",
            "messageType": 1,
            "alternativeMessageType": 1,
            "body": "Hello World",
            "createdTimestamp": "1663911908531",
            "sender": {
                "accountId": "8520698476712646544",
                "onlineId": "VaultTec_Trading"
            }
        }
    ],
    "previous": "1#425961448584099",
    "next": "1#425961448584099",
    "reachedEndOfPage": false,
    "messageCount": 1
}

get_group_information() GroupDetails[source]#

Gets the group chat information such as about me, avatars, languages etc…

Returns:

A dict containing info similar to what is shown below:

Raises:

PSNAWPNotFoundError – If group id does not exist or is invalid.

{
  "groupId": "~25C4C5406FD6D50E.763F9A1EB6AB5790",
  "groupType": 0,
  "modifiedTimestamp": "1663911908531",
  "groupName": {
    "value": "",
    "status": 0
  },
  "groupIcon": {
    "status": 0
  },
  "joinedTimestamp": "1616356026000",
  "isFavorite": false,
  "existsNewArrival": false,
  "mainThread": {
    "threadId": "~25C4C5406FD6D50E.763F9A1EB6AB5790",
    "modifiedTimestamp": "1663911908531",
    "latestMessage": {
      "messageUid": "1#425961448584099",
      "messageType": 1,
      "alternativeMessageType": 1,
      "body": "Hello World",
      "createdTimestamp": "1663911908531",
      "sender": {
        "accountId": "8520698476712646544",
        "onlineId": "VaultTec_Trading"
      }
    },
    "readMessageUid": "1#425961448584099"
  },
  "members": [
    {
      "accountId": "2721516955383551246",
      "onlineId": "VaultTec-Co"
    },
    {
      "accountId": "8520698476712646544",
      "onlineId": "VaultTec_Trading"
    }
  ],
  "partySessions": [],
  "notificationSetting": {
    "isMute": false
  }
}
invite_members(users: Iterable[User]) None[source]#

Invite users to join the group.

If all users in the invite list have blocked you, a PSNAWPForbidden exception is raised. Users who have blocked you are skipped, and the remaining users are invited.

Parameters:

users (Iterable[User]) – An iterable of User objects to be invited.

Raises:

PSNAWPForbiddenError – If all users in the invite list have blocked you.

kick_member(user: User) None[source]#

Remove a user from the group.

Parameters:

user – The User object representing the member to be removed.

Raises:

PSNAWPNotFoundError – If the user is not in the group.

leave_group() None[source]#

Leave the current group.

Raises:

PSNAWPNotFoundError – If you are not part of the group.

send_message(message: str) MessageResponse[source]#

Sends a message in the group.

Note

For now only text based messaging is supported.

Parameters:

message – Message Body

Returns:

A dict containing info similar to what is shown below:

{
    "messageUid": "1#425961448584099",
    "createdTimestamp": "1663911908531"
}