@@ -227,6 +227,91 @@ func (cli *Client) GetUserInfo(jids []types.JID) (map[types.JID]types.UserInfo,
227
227
return respData , nil
228
228
}
229
229
230
+ func (cli * Client ) parseBusinessProfile (node * waBinary.Node ) (* types.BusinessProfile , error ) {
231
+ profileNode := node .GetChildByTag ("profile" )
232
+ jid , ok := profileNode .AttrGetter ().GetJID ("jid" , true )
233
+ if ! ok {
234
+ return nil , errors .New ("missing jid in business profile" )
235
+ }
236
+ address := string (profileNode .GetChildByTag ("address" ).Content .([]byte ))
237
+ email := string (profileNode .GetChildByTag ("email" ).Content .([]byte ))
238
+ businessHour := profileNode .GetChildByTag ("business_hours" )
239
+ businessHourTimezone := businessHour .AttrGetter ().String ("timezone" )
240
+ businessHoursConfigs := businessHour .GetChildren ()
241
+ businessHours := make ([]types.BusinessHoursConfig , 0 )
242
+ for _ , config := range businessHoursConfigs {
243
+ if config .Tag != "business_hours_config" {
244
+ continue
245
+ }
246
+ dow := config .AttrGetter ().String ("dow" )
247
+ mode := config .AttrGetter ().String ("mode" )
248
+ openTime := config .AttrGetter ().String ("open_time" )
249
+ closeTime := config .AttrGetter ().String ("close_time" )
250
+ businessHours = append (businessHours , types.BusinessHoursConfig {
251
+ DayOfWeek : dow ,
252
+ Mode : mode ,
253
+ OpenTime : openTime ,
254
+ CloseTime : closeTime ,
255
+ })
256
+ }
257
+ categoriesNode := profileNode .GetChildByTag ("categories" )
258
+ categories := make ([]types.Category , 0 )
259
+ for _ , category := range categoriesNode .GetChildren () {
260
+ if category .Tag != "category" {
261
+ continue
262
+ }
263
+ id := category .AttrGetter ().String ("id" )
264
+ name := string (category .Content .([]byte ))
265
+ categories = append (categories , types.Category {
266
+ ID : id ,
267
+ Name : name ,
268
+ })
269
+ }
270
+ profileOptionsNode := profileNode .GetChildByTag ("profile_options" )
271
+ profileOptions := make (map [string ]string )
272
+ for _ , option := range profileOptionsNode .GetChildren () {
273
+ profileOptions [option .Tag ] = string (option .Content .([]byte ))
274
+ }
275
+ return & types.BusinessProfile {
276
+ JID : jid ,
277
+ Email : email ,
278
+ Address : address ,
279
+ Categories : categories ,
280
+ ProfileOptions : profileOptions ,
281
+ BusinessHoursTimeZone : businessHourTimezone ,
282
+ BusinessHours : businessHours ,
283
+ }, nil
284
+ }
285
+
286
+ // GetBusinessProfile gets the profile info of a WhatsApp business account
287
+ func (cli * Client ) GetBusinessProfile (jid types.JID ) (* types.BusinessProfile , error ) {
288
+ resp , err := cli .sendIQ (infoQuery {
289
+ Type : iqGet ,
290
+ To : types .ServerJID ,
291
+ Namespace : "w:biz" ,
292
+ Content : []waBinary.Node {{
293
+ Tag : "business_profile" ,
294
+ Attrs : waBinary.Attrs {
295
+ "v" : "244" ,
296
+ },
297
+ Content : []waBinary.Node {{
298
+ Tag : "profile" ,
299
+ Attrs : waBinary.Attrs {
300
+ "jid" : jid ,
301
+ },
302
+ }},
303
+ }},
304
+ })
305
+ if err != nil {
306
+ return nil , err
307
+ }
308
+ node , ok := resp .GetOptionalChildByTag ("business_profile" )
309
+ if ! ok {
310
+ return nil , & ElementMissingError {Tag : "business_profile" , In : "response to business profile query" }
311
+ }
312
+ return cli .parseBusinessProfile (& node )
313
+ }
314
+
230
315
// GetUserDevices gets the list of devices that the given user has. The input should be a list of
231
316
// regular JIDs, and the output will be a list of AD JIDs. The local device will not be included in
232
317
// the output even if the user's JID is included in the input. All other devices will be included.
0 commit comments