Add ChatSessionRequest capability
This commit is contained in:
@@ -28,6 +28,87 @@ class BaseCapability:
|
|||||||
|
|
||||||
# Please keep these in alphabetical order! :)
|
# Please keep these in alphabetical order! :)
|
||||||
|
|
||||||
|
@Capabilities.register("ChatSessionRequest")
|
||||||
|
class ChatSessionRequest(BaseCapability):
|
||||||
|
async def acceptInvitation(self, sessionId):
|
||||||
|
async with httpclient.HttpClient() as session:
|
||||||
|
async with await session.post(self.url,
|
||||||
|
data = llsd.llsdEncode({
|
||||||
|
"method": "accept invitation",
|
||||||
|
"session-id": sessionId
|
||||||
|
}),
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/llsd+xml"
|
||||||
|
}
|
||||||
|
) as response:
|
||||||
|
if response.status == 200:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
async def fetchHistory(self, sessionId):
|
||||||
|
"""
|
||||||
|
This returns a array in this format:
|
||||||
|
[{"from": ..., "from_id": ..., "message": ..., "num": ..., "time": ...}, ...]
|
||||||
|
"""
|
||||||
|
async with httpclient.HttpClient() as session:
|
||||||
|
async with await session.post(self.url,
|
||||||
|
data = llsd.llsdEncode({
|
||||||
|
"method": "fetch history",
|
||||||
|
"session-id": sessionId
|
||||||
|
}),
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/llsd+xml"
|
||||||
|
}
|
||||||
|
) as response:
|
||||||
|
if response.status != 200:
|
||||||
|
return []
|
||||||
|
|
||||||
|
data = await response.read()
|
||||||
|
result = llsd.llsdDecode(data, format="xml")
|
||||||
|
return result
|
||||||
|
|
||||||
|
async def startP2PVoice(self, sessionId, otherParticipantId):
|
||||||
|
async with httpclient.HttpClient() as session:
|
||||||
|
async with await session.post(self.url,
|
||||||
|
data = llsd.llsdEncode({
|
||||||
|
"method": "start p2p voice",
|
||||||
|
"session-id": sessionId,
|
||||||
|
"params": otherParticipantId,
|
||||||
|
"alt-params": {
|
||||||
|
"voice_server_type": "webrtc"
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/llsd+xml"
|
||||||
|
}
|
||||||
|
) as response:
|
||||||
|
if response.status == 200:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
async def startConference(self, sessionId, agents):
|
||||||
|
async with httpclient.HttpClient() as session:
|
||||||
|
async with await session.post(self.url,
|
||||||
|
data = llsd.llsdEncode({
|
||||||
|
"method": "start conference",
|
||||||
|
"session-id": sessionId,
|
||||||
|
"params": agents,
|
||||||
|
"alt-params": {
|
||||||
|
"voice_server_type": "webrtc"
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
headers = {
|
||||||
|
"Content-Type": "application/llsd+xml"
|
||||||
|
}
|
||||||
|
) as response:
|
||||||
|
if response.status == 200:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
@Capabilities.register("EventQueueGet")
|
@Capabilities.register("EventQueueGet")
|
||||||
class EventQueueGet(BaseCapability):
|
class EventQueueGet(BaseCapability):
|
||||||
async def poll(self, ack, done = False):
|
async def poll(self, ack, done = False):
|
||||||
@@ -69,4 +150,4 @@ class Seed(BaseCapability):
|
|||||||
if name in caps:
|
if name in caps:
|
||||||
result[name] = caps.get(name, url)
|
result[name] = caps.get(name, url)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
Reference in New Issue
Block a user