lemdaddy commited on
Commit
1e370f3
·
1 Parent(s): 660fb68

Add get user chatxbt id rpc method

Browse files
Files changed (1) hide show
  1. src/tools/user_profile_toolkit.py +26 -1
src/tools/user_profile_toolkit.py CHANGED
@@ -1,7 +1,10 @@
 
1
  import chainlit as cl
2
  from phi.tools import Toolkit
3
  from phi.utils.log import logger
4
 
 
 
5
 
6
  class UserProfileToolkit(Toolkit):
7
  def __init__(self):
@@ -16,6 +19,7 @@ class UserProfileToolkit(Toolkit):
16
  self.register(self.update_user_name)
17
  self.register(self.update_user_email)
18
  self.register(self.update_user_picture)
 
19
 
20
  @cl.on_chat_start
21
  def get_user_info(self, info_type: str) -> str:
@@ -163,7 +167,7 @@ class UserProfileToolkit(Toolkit):
163
  str: Confirmation message.
164
 
165
  Example:
166
- >>> update_user_email('jane.doe@example.com')
167
  """
168
  response = self.update_user_info('email', email)
169
  return f"{response}"
@@ -183,3 +187,24 @@ class UserProfileToolkit(Toolkit):
183
  """
184
  response = self.update_user_info('picture', picture)
185
  return f"{response}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
  import chainlit as cl
3
  from phi.tools import Toolkit
4
  from phi.utils.log import logger
5
 
6
+ from src.libs.rpc_client import rpc_call
7
+
8
 
9
  class UserProfileToolkit(Toolkit):
10
  def __init__(self):
 
19
  self.register(self.update_user_name)
20
  self.register(self.update_user_email)
21
  self.register(self.update_user_picture)
22
+ self.register(self.get_user_id)
23
 
24
  @cl.on_chat_start
25
  def get_user_info(self, info_type: str) -> str:
 
167
  str: Confirmation message.
168
 
169
  Example:
170
+ >>> update_user_email('jane.doe@chatxbt.com')
171
  """
172
  response = self.update_user_info('email', email)
173
  return f"{response}"
 
187
  """
188
  response = self.update_user_info('picture', picture)
189
  return f"{response}"
190
+
191
+ def get_user_id(self, user_email: str) -> str:
192
+ """
193
+ Fetches the ChatXBT ID of the user associated with the given email.
194
+
195
+ Args:
196
+ user_email (str): The email address of the user whose ChatXBT ID needs to be fetched.
197
+
198
+ Returns:
199
+ str]: A string containing the ChatXBT ID of the user. If the user is not found, an empty string is returned.
200
+
201
+ Example:
202
+ >>> get_user_id('jane.doe@chatxbt.com')
203
+ """
204
+ logger.info("Fetching user ChatXBT ID")
205
+
206
+ params = {
207
+ "userEmail": user_email.lower()
208
+ }
209
+ response = asyncio.run(rpc_call(method_name="getUserId", params=params))
210
+ return f"{response}"