@@ -39,7 +39,7 @@ async def wrapper(self, update: Update, context: CallbackContext):
3939 "ROS Bridge initialized to another chat_id. Type /start to connect to this chat_id"
4040 )
4141 else :
42- callback_function (self , update , context )
42+ await callback_function (self , update , context )
4343
4444 return wrapper
4545
@@ -58,7 +58,7 @@ def wrapper(self, msg):
5858 rospy .logerr ("ROS Bridge not initialized, dropping message of type %s" , msg ._type )
5959 else :
6060 try :
61- callback_function (self , msg )
61+ asyncio . run ( callback_function (self , msg ) )
6262 except TimedOut as e :
6363 rospy .logerr ("Telegram timeout: %s" , e )
6464
@@ -114,11 +114,11 @@ def _shutdown(self, reason: str):
114114 Sending a message to the current chat id on destruction.
115115 """
116116 if self ._telegram_chat_id :
117- self ._telegram_app .bot .send_message (
117+ asyncio . run ( self ._telegram_app .bot .send_message (
118118 self ._telegram_chat_id ,
119119 f"Stopping Telegram ROS bridge, ending this chat. Reason of shutdown: { reason } ."
120120 " Type /start to connect again after starting a new Telegram ROS bridge." ,
121- )
121+ ))
122122
123123 def spin (self ):
124124 """
@@ -196,14 +196,14 @@ async def _telegram_message_callback(self, update: Update, _: CallbackContext):
196196 self ._from_telegram_string_publisher .publish (String (data = text ))
197197
198198 @ros_callback
199- def _ros_string_callback (self , msg : String ):
199+ async def _ros_string_callback (self , msg : String ):
200200 """
201201 Called when a new ROS String message is coming in that should be sent to the Telegram conversation
202202
203203 :param msg: String message
204204 """
205205 if msg .data :
206- self ._telegram_app .bot .send_message (self ._telegram_chat_id , msg .data )
206+ await self ._telegram_app .bot .send_message (self ._telegram_chat_id , msg .data )
207207 else :
208208 rospy .logwarn ("Ignoring empty string message" )
209209
@@ -216,8 +216,8 @@ async def _telegram_photo_callback(self, update: Update, _: CallbackContext):
216216 :param update: Received update that holds the chat_id and message data
217217 """
218218 rospy .logdebug ("Received image, downloading highest resolution image ..." )
219- new_file = asyncio . run ( update .message .photo [- 1 ].get_file () )
220- byte_array = asyncio . run ( new_file .download_as_bytearray () )
219+ new_file = await update .message .photo [- 1 ].get_file ()
220+ byte_array = await new_file .download_as_bytearray ()
221221 rospy .logdebug ("Download complete, publishing ..." )
222222
223223 img = cv2 .imdecode (np .asarray (byte_array , dtype = np .uint8 ), cv2 .IMREAD_COLOR )
@@ -232,14 +232,14 @@ async def _telegram_photo_callback(self, update: Update, _: CallbackContext):
232232 self ._from_telegram_string_publisher .publish (String (data = update .message .caption ))
233233
234234 @ros_callback
235- def _ros_image_callback (self , msg : Image ):
235+ async def _ros_image_callback (self , msg : Image ):
236236 """
237237 Called when a new ROS Image message is coming in that should be sent to the Telegram conversation
238238
239239 :param msg: Image message
240240 """
241241 cv2_img = self ._cv_bridge .imgmsg_to_cv2 (msg , "bgr8" )
242- self ._telegram_app .bot .send_photo (
242+ await self ._telegram_app .bot .send_photo (
243243 self ._telegram_chat_id ,
244244 photo = BytesIO (cv2 .imencode (".jpg" , cv2_img )[1 ].tobytes ()),
245245 caption = msg .header .frame_id ,
@@ -263,16 +263,16 @@ async def _telegram_location_callback(self, update: Update, _: CallbackContext):
263263 )
264264
265265 @ros_callback
266- def _ros_location_callback (self , msg : NavSatFix ):
266+ async def _ros_location_callback (self , msg : NavSatFix ):
267267 """
268268 Called when a new ROS NavSatFix message is coming in that should be sent to the Telegram conversation
269269
270270 :param msg: NavSatFix that the robot wants to share
271271 """
272- self ._telegram_app .bot .send_location (self ._telegram_chat_id , location = Location (msg .longitude , msg .latitude ))
272+ await self ._telegram_app .bot .send_location (self ._telegram_chat_id , location = Location (msg .longitude , msg .latitude ))
273273
274274 @ros_callback
275- def _ros_options_callback (self , msg : Options ):
275+ async def _ros_options_callback (self , msg : Options ):
276276 """
277277 Called when a new ROS Options message is coming in that should be sent to the Telegram conversation
278278
@@ -284,7 +284,7 @@ def chunks(l, n): # noqa: E741
284284 for i in range (0 , len (l ), n ):
285285 yield l [i : i + n ] # noqa: E203
286286
287- self ._telegram_app .bot .send_message (
287+ await self ._telegram_app .bot .send_message (
288288 self ._telegram_chat_id ,
289289 text = msg .question ,
290290 reply_markup = ReplyKeyboardMarkup (
0 commit comments