Module: Qismo::Api

Includes:
Client
Included in:
Client
Defined in:
lib/qismo/api.rb

Overview

API wrappers

Instance Method Summary collapse

Instance Method Details

#add_room_tag(room_id:, tag:) ⇒ Qismo::Objects::Tag

Add room tag

Parameters:

  • room_id (Integer)
  • tag (String)

    Tag name

Returns:

See Also:



95
96
97
98
99
# File 'lib/qismo/api.rb', line 95

def add_room_tag(room_id:, tag:)
  Qismo::Objects::Tag.new(
    post("/api/v2/room_tags/#{room_id}", tag: tag).data
  )
end

#allocate_agent(source:, channel_id:, ignore_availability: false) ⇒ Qismo::Objects::User

Get agent that can be assigned to room

Parameters:

  • source (String)

    Channel source. Available sources are ‘wa`, `line`, `telegram`, `qiscus`, `ig`, or `fb`. For custom channel, use that channel’s identifier_key as source

  • channel_id (Integer)

    The channel id you want to allocate

  • ignore_availability (TrueClass, FalseClass) (defaults to: false)

    Ignore agent availability. If you set this param to true, agent that are unavailable will be considered as allocatable too

Returns:

See Also:



256
257
258
259
260
261
262
263
264
# File 'lib/qismo/api.rb', line 256

def allocate_agent(source:, channel_id:, ignore_availability: false)
  Qismo::Objects::User.new(
    post("/api/v1/admin/service/allocate_agent", {
      source: source,
      channel_id: channel_id,
      ignore_availability: ignore_availability
    }).data.agent
  )
end

#allocate_and_assign_agent(room_id:, ignore_availability: false) ⇒ Qismo::Objects::User

Get agent that can be allocated to room and automatically assign them

Parameters:

  • room_id (Integer)
  • ignore_availability (TrueClass, FalseClass) (defaults to: false)

    Ignore agent availability. If you set this param to true, agent that are unavailable will be considered as allocatable too

Returns:

See Also:



274
275
276
277
278
279
280
281
# File 'lib/qismo/api.rb', line 274

def allocate_and_assign_agent(room_id:, ignore_availability: false)
  Qismo::Objects::User.new(
    post("/api/v1/admin/service/allocate_assign_agent", {
      room_id: room_id.to_s,
      ignore_availability: ignore_availability
    }).data.agent
  )
end

#assign_agent(room_id:, agent_id:, replace_latest_agent: false, max_agent: nil) ⇒ Qismo::Objects::User

Assign an agent to a room

Parameters:

  • room_id (Integer)
  • agent_id (Integer)
  • replace_latest_agent (TrueClass, FalseClass) (defaults to: false)

    Replace agents in room or not. Don’t combine this param with :max_agent param

  • max_agent (Integer) (defaults to: nil)

    Specify max agent that can be assigned to a room. For example, if there are 1 agent in a room and you specific max_agent to 1, you will get bad request error. If you set param :replace_latest_agent to true, this param will be forced to nil, which no be sent on http request

Returns:



187
188
189
190
191
192
193
194
195
196
# File 'lib/qismo/api.rb', line 187

def assign_agent(room_id:, agent_id:, replace_latest_agent: false, max_agent: nil)
  Qismo::Objects::User.new(
    post("/api/v1/admin/service/assign_agent", {
      room_id: room_id.to_s,
      agent_id: agent_id,
      replace_latest_agent: replace_latest_agent,
      max_agent: (replace_latest_agent == true) ? nil : max_agent
    }).data.assign_agent
  )
end

#create_auth_webhook(url:, enabled: true) ⇒ Qismo::Objects::Webhook

Set auth webhook

Parameters:

  • url (String)
  • enabled (TrueClass, FalseClass) (defaults to: true)

Returns:



375
376
377
378
379
380
381
# File 'lib/qismo/api.rb', line 375

def create_auth_webhook(url:, enabled: true)
  config = post("/api/v2/app/config/auth_webhook", url: url, enabled: enabled).data.configs
  Qismo::Objects::Webhook.new(
    enabled: config.is_auth_webhook_enabled,
    url: config.auth_webhook_url
  )
end

#create_new_session_webhook(url:, enabled: true) ⇒ Qismo::Objects::Webhook

Set new session webhook

Parameters:

  • url (String)
  • enabled (TrueClass, FalseClass) (defaults to: true)

Returns:



351
352
353
354
355
356
357
# File 'lib/qismo/api.rb', line 351

def create_new_session_webhook(url:, enabled: true)
  config = post("/api/v2/app/config/new_session_webhook", url: url, enabled: enabled).data.configs
  Qismo::Objects::Webhook.new(
    enabled: config.is_new_session_webhook_enabled,
    url: config.new_session_webhook_url
  )
end

#create_resolve_webhook(url:, enabled: true) ⇒ Qismo::Objects::Webhook

Set resolve webhook

Parameters:

  • url (String)
  • options (Hash)

Returns:



399
400
401
402
403
404
405
# File 'lib/qismo/api.rb', line 399

def create_resolve_webhook(url:, enabled: true)
  config = post("/api/v1/app/webhook/mark_as_resolved", webhook_url: url, is_webhook_enabled: enabled).data
  Qismo::Objects::Webhook.new(
    enabled: config.is_mark_as_resolved_webhook_enabled,
    url: config.mark_as_resolved_webhook_url
  )
end

#create_room_info(room_id:, info:) ⇒ Array<Qismo::Objects::RoomAdditionalInfo>

Note:

This will replace your current room additional info

Set room additional info

Parameters:

  • room_id (Integer)
  • info (Array<Hash>)

    Key value pair of additional info. Ex: [{ key: “Ticket Link”, value: “ticket.com” }]

Returns:

See Also:



133
134
135
136
137
138
139
140
# File 'lib/qismo/api.rb', line 133

def create_room_info(room_id:, info:)
  Qismo::Objects::RoomAdditionalInfo.from_array(
    post(
      "/api/v1/qiscus/room/#{room_id}/user_info",
      user_properties: info
    ).data.extras.user_properties
  )
end

#delete_room_tag(room_id:, tag_id:) ⇒ TrueClass

Delete room tag

Parameters:

  • room_id (Integer)
  • tag_id (Integer)

Returns:

  • (TrueClass)

See Also:



107
108
109
110
# File 'lib/qismo/api.rb', line 107

def delete_room_tag(room_id:, tag_id:)
  delete("/api/v2/room_tags/#{room_id}/#{tag_id}")
  true
end

#disable_bot_in_room(room_id:) ⇒ TrueClass

Disable chatbot in room

Parameters:

  • room_id (Integer)

Returns:

  • (TrueClass)

See Also:



724
725
726
727
# File 'lib/qismo/api.rb', line 724

def disable_bot_in_room(room_id:)
  post("/bot/#{room_id}/activate", is_active: false)
  true
end

#enable_bot_in_room(room_id:) ⇒ TrueClass

Enable chabot in room

Parameters:

  • room_id (Integer)

Returns:

  • (TrueClass)

See Also:



714
715
716
717
# File 'lib/qismo/api.rb', line 714

def enable_bot_in_room(room_id:)
  post("/bot/#{room_id}/activate", is_active: true)
  true
end

#get_agent(agent_id:) ⇒ Qismo::Objects::User

Get agent by id



474
475
476
# File 'lib/qismo/api.rb', line 474

def get_agent(agent_id:)
  Qismo::Objects::User.new(get("/api/v2/admin/agent/#{agent_id}").data.agent)
end

#get_auth_webhookQismo::Objects::Webhook

Get auth webhook config



362
363
364
365
366
367
368
# File 'lib/qismo/api.rb', line 362

def get_auth_webhook
  config = get("/api/v2/app/config/auth_webhook").data.configs
  Qismo::Objects::Webhook.new(
    enabled: config.is_auth_webhook_enabled,
    url: config.auth_webhook_url
  )
end

#get_new_session_webhookQismo::Objects::Webhook

Get new session webhook config



338
339
340
341
342
343
344
# File 'lib/qismo/api.rb', line 338

def get_new_session_webhook
  config = get("/api/v2/app/config/new_session_webhook").data.configs
  Qismo::Objects::Webhook.new(
    enabled: config.is_new_session_webhook_enabled,
    url: config.new_session_webhook_url
  )
end

#get_office_hoursQismo::Objects::OfficeHour

Get office hour config



482
483
484
485
486
# File 'lib/qismo/api.rb', line 482

def get_office_hours
  Qismo::Objects::OfficeHour.new(
    get("/api/v1/admin/office_hours").data
  )
end

#get_profileObject



9
10
11
12
# File 'lib/qismo/api.rb', line 9

def get_profile
  body = get("/api/v1/admin/get_profile")
  Qismo::Objects::AdminProfile.new(body.data)
end

#get_resolve_webhookQismo::Objects::Webhook

Get resolve webhook config



386
387
388
389
390
391
392
# File 'lib/qismo/api.rb', line 386

def get_resolve_webhook
  config = get("/api/v1/app/webhook/mark_as_resolved").data
  Qismo::Objects::Webhook.new(
    enabled: config.is_mark_as_resolved_webhook_enabled,
    url: config.mark_as_resolved_webhook_url
  )
end

#get_room(room_id:) ⇒ Qismo::Objects::CustomerRoom

Get room by id



66
67
68
69
70
71
72
73
# File 'lib/qismo/api.rb', line 66

def get_room(room_id:)
  body = get("/api/v2/customer_rooms/#{room_id}")
  if body.data.customer_room.nil?
    raise Qismo::NotFoundError.new("Room not found", status_code: 404, response_body: body.to_json)
  end

  Qismo::Objects::CustomerRoom.new(body.data.customer_room)
end

#get_wa_broadcast_job(broadcast_job_id:) ⇒ Qismo::Objects::BroadcastJob

Get wa broadcast job by id



655
656
657
658
659
# File 'lib/qismo/api.rb', line 655

def get_wa_broadcast_job(broadcast_job_id:)
  Qismo::Objects::BroadcastJob.new(
    get("/api/v2/admin/broadcast_jobs/#{broadcast_job_id}").data.broadcast_job
  )
end

#get_wa_creditQismo::Objects::WaCreditInfo

Get Whatsapp channel credit info



515
516
517
518
519
# File 'lib/qismo/api.rb', line 515

def get_wa_credit
  Qismo::Objects::WaCreditInfo.new(
    get("/api/v2/admin/wa_pricing/balance").data
  )
end

#handover_room_from_bot(room_id:) ⇒ TrueClass

Handover room from chatbot to human agent

Parameters:

  • room_id (Integer)

Returns:

  • (TrueClass)

See Also:



734
735
736
737
738
739
740
# File 'lib/qismo/api.rb', line 734

def handover_room_from_bot(room_id:)
  request(:post, "/#{app_id}/bot/#{room_id}/hand_over", headers: {
    Authorization: secret_key
  })

  true
end

#handover_room_from_bot_to_division(room_id:, roles:, find_online_agent: true) ⇒ TrueClass, FalseClass

Handover room from chatbot to human agent in specific divisions

Parameters:

  • room_id (Integer)
  • roles (Integer, Array<Integer>)
  • find_online_agent (TrueClass, FalseClass) (defaults to: true)

Returns:

  • (TrueClass, FalseClass)

See Also:



750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
# File 'lib/qismo/api.rb', line 750

def handover_room_from_bot_to_division(room_id:, roles:, find_online_agent: true)
  options = {}
  options[:room_id] = room_id.to_s
  options[:find_online_agent] = find_online_agent

  if roles.is_a?(Array)
    options[:roles] = roles
  else
    options[:role] = roles
  end

  request(
    :post,
    "/#{app_id}/bot/#{room_id}/hand_over_to_role",
    headers: {Authorization: secret_key},
    json: options
  )

  true
end

#initiate_widget_chat(user_id:, name:, nonce: nil, channel_id: nil, extras: nil, reset_extras: false, room_badge: nil, avatar: nil, allocate_agent: nil, user_properties: nil, sdk_user_extras: nil, timezone_offset: nil, notes: nil, phone_number: nil, email: nil) ⇒ Qismo::Objects::CustomerRoom

Initiate chat using Qiscus widget channel

Parameters:

  • user_id (String)
  • name (String)
  • nonce (String) (defaults to: nil)
  • channel_id (Integer) (defaults to: nil)
  • extras (Hash) (defaults to: nil)
  • reset_extras (TrueClass, FalseClass) (defaults to: false)
  • room_badge (String) (defaults to: nil)
  • avatar (String) (defaults to: nil)
  • allocate_agent (TrueClass, FalseClass) (defaults to: nil)
  • user_properties (Hash) (defaults to: nil)
  • sdk_user_extras (Hash) (defaults to: nil)
  • timezone_offset (String) (defaults to: nil)
  • notes (String) (defaults to: nil)
  • phone_number (String) (defaults to: nil)
  • email (String) (defaults to: nil)

Returns:

See Also:



790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
# File 'lib/qismo/api.rb', line 790

def initiate_widget_chat(user_id:, name:, nonce: nil, channel_id: nil, extras: nil, reset_extras: false, room_badge: nil, avatar: nil, allocate_agent: nil, user_properties: nil, sdk_user_extras: nil, timezone_offset: nil, notes: nil, phone_number: nil, email: nil)
  options = {
    user_id: user_id,
    name: name,
    nonce: nonce,
    channel_id: channel_id,
    extras: extras,
    reset_extras: reset_extras,
    room_badge: room_badge,
    avatar: avatar,
    allocate_agent: allocate_agent,
    user_properties: user_properties,
    sdk_user_extras: sdk_user_extras,
    timezone_offset: timezone_offset,
    notes: notes,
    phone_number: phone_number,
    email: email
  }.compact

  options[:app_id] = app_id

  Qismo::Objects::CustomerRoom.new(post("/api/v2/qiscus/initiate_chat", options).data.customer_room)
end

#list_agents(page: 1, limit: 10, search: nil, scope: nil) ⇒ Qismo::Collection<Qismo::Objects::User>

List agents



412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/qismo/api.rb', line 412

def list_agents(page: 1, limit: 10, search: nil, scope: nil)
  body = get("/api/v2/admin/agents", {
    page: page,
    limit: limit,
    search: search,
    scope: scope
  })

  total_page = (body.meta.total_count.to_f / body.meta.per_page.to_f).ceil

  Qismo::Collection.new(
    Qismo::Objects::User.from_array(body.data.agents),
    next_page: ((page < total_page) ? (page + 1) : nil),
    prev_page: ((page > 1) ? (page - 1) : nil)
  )
end

#list_agents_by_divisions(division_ids, page: 1, limit: 10, is_available: nil, sort: "asc") ⇒ Qismo::Collection<Qismo::Objects::User>

List agents by divisions

Parameters:

  • division_ids (Array<Integer>)
  • page (Integer) (defaults to: 1)

    Page number

  • limit (Integer) (defaults to: 10)

    Number of data returned in one page

  • is_available (TrueClass, FalseClass) (defaults to: nil)

    Filter only available or unavailable agents

  • sort (String) (defaults to: "asc")

    Sort result by descending or ascending

Returns:

See Also:



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/qismo/api.rb', line 453

def list_agents_by_divisions(division_ids, page: 1, limit: 10, is_available: nil, sort: "asc")
  body = get("/api/v2/admin/agents/by_division", {
    "division_ids[]": division_ids,
    page: page,
    limit: limit,
    is_available: is_available,
    sort: sort
  })

  Qismo::Collection.new(
    Qismo::Objects::User.from_array(body.data),
    next_page: ((body.meta.page < body.meta.total_page) ? (body.meta.page + 1) : nil),
    prev_page: ((body.meta.page > 1) ? (body.meta.page - 1) : nil)
  )
end

#list_agents_by_ids(agent_ids:) ⇒ Qismo::Collection<Qismo::Objects::User>

List agents by ids



434
435
436
437
438
# File 'lib/qismo/api.rb', line 434

def list_agents_by_ids(agent_ids:)
  Qismo::Collection.new(
    Qismo::Objects::User.from_array(get("/api/v1/admin/agents/get_by_ids", {"ids[]": agent_ids}).data)
  )
end

#list_available_agents(room_id:, is_available_in_room: true, search: nil, limit: 15, cursor_after: nil, cursor_before: nil) ⇒ Qismo::Collection<Qismo::Objects::User>

List available agents in room

Parameters:

  • room_id (Integer)
  • is_available_in_room (TrueClass, FalseClass) (defaults to: true)
  • search (String) (defaults to: nil)
  • limit (Integer) (defaults to: 15)
  • cursor_after (String) (defaults to: nil)
  • cursor_before (String) (defaults to: nil)

Returns:

See Also:



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/qismo/api.rb', line 318

def list_available_agents(room_id:, is_available_in_room: true, search: nil, limit: 15, cursor_after: nil, cursor_before: nil)
  body = get("/api/v2/admin/service/available_agents", {
    room_id: room_id.to_s,
    is_available_in_room: is_available_in_room,
    search: search,
    limit: limit,
    cursor_after: cursor_after,
    cursor_before: cursor_before
  })

  Collection.new(
    Qismo::Objects::User.from_array(body.data.agents),
    next_page: body.meta.cursor_after,
    prev_page: body.meta.cursor_before
  )
end

#list_channelsQismo::Objects::ListChannelsResponse

List integrated channels



854
855
856
857
858
# File 'lib/qismo/api.rb', line 854

def list_channels
  Qismo::Objects::ListChannelsResponse.new(
    get("/api/v2/channels").data
  )
end

#list_other_agents(room_id:, search: nil, limit: 15, cursor_after: nil, cursor_before: nil) ⇒ Qismo::Collection<Qismo::Objects::User>

List agents that are not in room and can be assigned to room

Parameters:

  • room_id (Integer)
  • search (String) (defaults to: nil)
  • limit (Integer) (defaults to: 15)
  • cursor_after (String) (defaults to: nil)
  • cursor_before (String) (defaults to: nil)

Returns:

See Also:



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/qismo/api.rb', line 292

def list_other_agents(room_id:, search: nil, limit: 15, cursor_after: nil, cursor_before: nil)
  body = get("/api/v2/admin/service/other_agents", {
    room_id: room_id.to_s,
    search: search,
    limit: limit,
    cursor_after: cursor_after,
    cursor_before: cursor_before
  })

  Collection.new(
    Qismo::Objects::User.from_array(body.data.agents),
    next_page: body.meta.cursor_after,
    prev_page: body.meta.cursor_before
  )
end

#list_room_broadcasts(room_id:, page: 1, limit: 25) ⇒ Qismo::Collection<Qismo::Objects::BroadcastLog>

List broadcast history inside room

Parameters:

  • room_id (Integer)
  • page (Integer) (defaults to: 1)
  • limit (Integer) (defaults to: 25)

Returns:



160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/qismo/api.rb', line 160

def list_room_broadcasts(room_id:, page: 1, limit: 25)
  body = get("/api/v2/customer_rooms/#{room_id}/broadcast_history", {
    page: page,
    limit: limit
  })

  Qismo::Collection.new(
    Qismo::Objects::BroadcastLog.from_array(body.data.broadcast_logs),
    next_page: ((body.meta.page < body.dig("meta", "total_page")) ? (body.meta.page + 1) : nil),
    prev_page: ((body.meta.page > 1) ? (body.meta.page - 1) : nil)
  )
end

#list_room_info(room_id:) ⇒ Array<Qismo::Objects::RoomAdditionalInfo>

List room additional info



117
118
119
120
121
122
123
# File 'lib/qismo/api.rb', line 117

def list_room_info(room_id:)
  Qismo::Objects::RoomAdditionalInfo.from_array(
    get("/api/v1/qiscus/room/#{room_id}/user_info").data.extras.user_properties
  )
rescue NoMethodError
  Qismo::Objects::RoomAdditionalInfo.from_array([])
end

#list_room_tags(room_id:) ⇒ Qismo::Collection<Qismo::Objects::Tag>

List tags inside room



80
81
82
83
84
85
86
# File 'lib/qismo/api.rb', line 80

def list_room_tags(room_id:)
  Qismo::Collection.new(
    Qismo::Objects::Tag.from_array(
      get("/api/v2/room_tags/#{room_id}").data
    )
  )
end

#list_rooms(channels: nil, status: nil, serve_status: nil, name: nil, limit: 50, tag_ids: nil, user_ids: nil, order: "desc", cursor_after: nil, cursor_before: nil, is_handled_by_bot: nil) ⇒ Qismo::Collection<Qismo::CustomerRoom>

List customer rooms

Parameters:

  • channels (Array<Hash>) (defaults to: nil)

    Filter rooms by channels. Example: [{ source: “wa”, channel_id: 716171 }]

  • status (String) (defaults to: nil)

    Filter rooms by status. Valid values are “resolved”, “unresolved”, “expired”,or “almost_expired”

  • serve_status (String) (defaults to: nil)

    Filter rooms by serve status. Valid values are “served” or “unserved”. By default, we will retrieve all serve_status

  • name (String) (defaults to: nil)

    Filter rooms by customer nam

  • limit (Integer) (defaults to: 50)

    Limit the number of rooms returned in one page. By default, it will return 50 rooms data

  • tag_ids (Array<Integer>) (defaults to: nil)

    Filter rooms by its tag

  • user_ids (Array<Integer>) (defaults to: nil)

    Filter rooms by the agent who handled the rooms

  • order (String) (defaults to: "desc")

    Order returned data by the timestamp. By default, we will return the newest rooms first

  • cursor_after (String) (defaults to: nil)

    Next page cursor. If you are on last page, the cursor returned will be nil

  • cursor_before (String) (defaults to: nil)

    Previous page cursor. If you are on first page, the cursor returned will be nil

  • is_handled_by_bot (TrueClass, FalseClass) (defaults to: nil)

    Filter rooms by chatbot activation status in room

Returns:

See Also:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/qismo/api.rb', line 40

def list_rooms(channels: nil, status: nil, serve_status: nil, name: nil, limit: 50, tag_ids: nil, user_ids: nil, order: "desc", cursor_after: nil, cursor_before: nil, is_handled_by_bot: nil)
  body = post("/api/v2/customer_rooms", {
    channels: channels,
    status: status,
    serve_status: serve_status,
    name: name,
    limit: limit,
    tag_ids: tag_ids,
    user_ids: user_ids,
    order: order,
    cursor_after: cursor_after,
    cursor_before: cursor_before,
    is_handled_by_bot: is_handled_by_bot
  })

  Collection.new(
    Qismo::Objects::CustomerRoom.from_array(body.data.customer_rooms),
    next_page: body.meta.cursor_after,
    prev_page: body.meta.cursor_before
  )
end

#list_wa_broadcast_jobs(limit: 10, cursor_after: nil, cursor_before: nil, name: nil) ⇒ Qismo::Collection<Qismo::Objects::BroadcastJob>

List WA broadcast jobs

Parameters:

  • page (Integer)
  • limit (Integer) (defaults to: 10)
  • cursor_after (Integer) (defaults to: nil)
  • cursor_before (Integer) (defaults to: nil)
  • name (String) (defaults to: nil)

Returns:



635
636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'lib/qismo/api.rb', line 635

def list_wa_broadcast_jobs(limit: 10, cursor_after: nil, cursor_before: nil, name: nil)
  body = get("/api/v2/admin/broadcast_jobs", {
    limit: limit,
    cursor_after: cursor_after,
    cursor_before: cursor_before,
    name: name
  })

  Qismo::Collection.new(
    Qismo::Objects::BroadcastJob.from_array(body.data.broadcast_jobs),
    next_page: body.meta.cursor_after,
    prev_page: body.meta.cursor_before
  )
end

#list_wa_broadcast_logs(broadcast_job_id:, page: 1, limit: 10) ⇒ Qismo::Collection<Qismo::Objects::BroadcastLog>

List wa broadcast logs



667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
# File 'lib/qismo/api.rb', line 667

def list_wa_broadcast_logs(broadcast_job_id:, page: 1, limit: 10)
  body = get("/api/v2/admin/broadcast_logs/#{broadcast_job_id}", {
    page: page,
    limit: limit
  })

  prev_page = (body.meta.page > 1) ? (body.meta.meta - 1) : nil
  next_page = (body.meta.page < body.meta.total_page) ? (body.meta.page + 1) : nil

  Qismo::Collection.new(
    Qismo::Objects::BroadcastLog.from_array(body.data.broadcast_logs),
    next_page: next_page,
    prev_page: prev_page
  )
end

#list_wa_broadcast_templates(page: 1, limit: 10, approved: nil) ⇒ Qismo::Collection<Qismo::Objects::HsmTemplate>

List WA broadcast templates

Parameters:

  • page (Integer) (defaults to: 1)

    Page number

  • limit (Integer) (defaults to: 10)

    Number of data returned in one page

  • approved (TrueClass, FalseClass) (defaults to: nil)

    Filter template by approval status

Returns:

See Also:



498
499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/qismo/api.rb', line 498

def list_wa_broadcast_templates(page: 1, limit: 10, approved: nil)
  body = get("/api/v3/admin/hsm", {
    page: page,
    limit: limit,
    approved: approved
  })

  Qismo::Collection.new(
    Qismo::Objects::HsmTemplate.from_array(body.data.hsm_templates),
    next_page: ((body.meta.page < body.meta.total_page) ? (body.meta.page + 1) : nil),
    prev_page: ((body.meta.page > 1) ? (body.meta.page - 1) : nil)
  )
end

#remove_agent(room_id:, agent_id:) ⇒ TrueClass

Remove agent from room

Parameters:

  • room_id (Integer)
  • agent_id (Integer)

Returns:

  • (TrueClass)

See Also:



204
205
206
207
208
209
210
211
212
213
# File 'lib/qismo/api.rb', line 204

def remove_agent(room_id:, agent_id:)
  post(
    "/api/v1/admin/service/remove_agent", {
      room_id: room_id.to_s,
      agent_id: agent_id
    }
  )

  true
end

#resolve_room(room_id:, last_comment_id: Time.now.to_i, notes: nil, is_send_email: false, extras: nil) ⇒ Qismo::Objects::AgentService

Resolve room

Parameters:

  • room_id (Integer)
  • last_comment_id (Integer) (defaults to: Time.now.to_i)

    Id of last message in the room. If you dont specify this param, we will use current epoc timestamp

  • notes (String) (defaults to: nil)

    Specify room notes. You can also use simple markdown markup for this param

  • is_send_email (TrueClass, FalseClass) (defaults to: false)

    Send email to customer or no. This param will only worked if you are using valid email as customer identifier

  • extras (Hash) (defaults to: nil)

    Room extras in valid hash

Returns:

See Also:



231
232
233
234
235
236
237
238
239
240
241
# File 'lib/qismo/api.rb', line 231

def resolve_room(room_id:, last_comment_id: Time.now.to_i, notes: nil, is_send_email: false, extras: nil)
  Qismo::Objects::AgentService.new(
    post("/api/v1/admin/service/mark_as_resolved", {
      room_id: room_id.to_s,
      last_comment_id: last_comment_id,
      notes: notes,
      is_send_email: is_send_email,
      extras: extras
    }).data.service
  )
end

#send_bot_message(room_id:, message:, type: "text", payload: {}, extras: {}) ⇒ TrueClass

Send message as bot

Parameters:

  • room_id (Integer)
  • message (String)
  • type (String) (defaults to: "text")
  • payload (Hash) (defaults to: {})
  • extras (Hash) (defaults to: {})

Returns:

  • (TrueClass)

See Also:



692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
# File 'lib/qismo/api.rb', line 692

def send_bot_message(room_id:, message:, type: "text", payload: {}, extras: {})
  body = post("/#{app_id}/bot", {
    sender_email: admin_email,
    room_id: room_id.to_s,
    message: message,
    type: type,
    payload: payload,
    extras: extras
  })

  if body != "ok"
    raise Qismo::BadRequestError.new(body.to_s, status_code: 400, response_body: body.to_s)
  end

  true
end

#send_message_to_custom_channel(identifier_key:, user_id:, name:, message:, avatar: nil, type: "text", payload: {}, extras: {}) ⇒ Qismo::Objects::CustomChannelMessageResponse

Send messsage to custom channel

Parameters:

  • identifier_key (String)
  • user_id (String)
  • name (String)
  • message (String)
  • avatar (String) (defaults to: nil)
  • type (String) (defaults to: "text")
  • payload (Hash) (defaults to: {})
  • extras (Hash) (defaults to: {})

Returns:

See Also:



826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
# File 'lib/qismo/api.rb', line 826

def send_message_to_custom_channel(
  identifier_key:,
  user_id:,
  name:,
  message:,
  avatar: nil,
  type: "text",
  payload: {},
  extras: {}
)
  Qismo::Objects::CustomChannelMessageResponse.new(
    post("/#{app_id}/api/v2/custom_channel/send", {
      identifier_key: identifier_key,
      user_id: user_id,
      name: name,
      message: message,
      avatar: avatar,
      type: type,
      payload: payload,
      extras: extras
    }).data
  )
end

#send_wa_broadcast(file:, template_detail_id:, name: nil, separator: ",", started_at: nil) ⇒ Qismo::Objects::BroadcastJob

Send WA broadcast

Parameters:

  • file (HTTP::FormData::File, Integer)
  • template_detail_id (Integer)
  • name (String) (defaults to: nil)
  • separator (String) (defaults to: ",")
  • started_at (Time) (defaults to: nil)

Returns:

See Also:



595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
# File 'lib/qismo/api.rb', line 595

def send_wa_broadcast(file:, template_detail_id:, name: nil, separator: ",", started_at: nil)
  if name.blank?
    name = default_broadcast_name
  end

  if started_at.present? && !started_at.is_a?(Time)
    unless started_at.is_a?(Time)
      raise ArgumentError, "You must past :Time class for this parameter"
    end

    unless started_at.utc_offset == 0
      raise ArgumentError, "You must set your timezone to UTC"
    end
  end

  file_id = if file.is_a?(HTTP::FormData::File)
    upload_wa_broadcast_csv(file, template_detail_id, separator: separator)
  else
    file.to_i
  end

  Qismo::Objects::BroadcastJob.new(
    post("/api/v3/admin/broadcast/send_broadcast", {
      broadcast_file_id: file_id,
      name: name,
      separator: separator,
      started_at: started_at,
      template_detail_id: template_detail_id
    }).data.broadcast_job
  )
end

#send_wa_outbound(phone_number:, template_detail_id: nil, channel_id: nil, template_name: nil, namespace: nil, language: nil, variables: [], button_params: nil, header_value: nil) ⇒ Qismo::Objects::BroadcastJob

Send WA outbound message

Parameters:

  • phone_number (String)
  • channel_id (Integer) (defaults to: nil)
  • template_name (String) (defaults to: nil)
  • namespace (String) (defaults to: nil)
  • language (String) (defaults to: nil)
  • template_detail_id (Integer) (defaults to: nil)
  • variables (Array<String>) (defaults to: [])
  • button_params (Array<Hash>) (defaults to: nil)
  • header_value (Hash) (defaults to: nil)

Returns:

See Also:



534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
# File 'lib/qismo/api.rb', line 534

def send_wa_outbound(
  phone_number:,
  template_detail_id: nil,
  channel_id: nil,
  template_name: nil,
  namespace: nil,
  language: nil,
  variables: [],
  button_params: nil,
  header_value: nil
)
  if template_detail_id.nil?
    raise ArgumentError, ":channel_id is required if you dont use :template_detail_id" if channel_id.nil?
    raise ArgumentError, ":template_name is required if you dont use :template_detail_id" if template_name.nil?
    raise ArgumentError, ":namespace is required if you dont use :template_detail_id" if namespace.nil?
    raise ArgumentError, ":language is required if you dont use :template_detail_id" if language.nil?
  end

  body = post("/api/v3/admin/broadcast/client", {
    phone_number: phone_number,
    template_detail_id: template_detail_id,
    channel_id: channel_id,
    template_name: template_name,
    namespace: namespace,
    language: language,
    variables: variables,
    button_params: button_params,
    header_value: header_value
  })

  Qismo::Objects::BroadcastJob.new(body.data)
end

#update_room_info(room_id:, info:) ⇒ Array<Qismo::Objects::RoomAdditionalInfo>

Update room additional info

Parameters:

  • room_id (Integer)
  • info (Array<Hash>)

    Key value pair of additional info. Ex: [{ key: “Ticket Link”, value: “ticket.com” }]

Returns:



148
149
150
151
152
# File 'lib/qismo/api.rb', line 148

def update_room_info(room_id:, info:)
  old_info = room_additional_info(room_id).as_json
  new_info = (info.as_json + old_info).uniq { |h| h.values_at("key") }
  set_room_additional_info(room_id: room_id, info: new_info)
end

#upload_wa_broadcast_csv(file:, template_detail_id:, separator: ",") ⇒ Integer

Upload wa broadcast file that want to be sent in broadcast

Parameters:

  • file (HTTP::FormData)
  • template_detail_id (Integer)
  • separator (String) (defaults to: ",")

Returns:

  • (Integer)

Raises:

  • (ArgumentError)

See Also:



574
575
576
577
578
579
580
581
582
583
584
# File 'lib/qismo/api.rb', line 574

def upload_wa_broadcast_csv(file:, template_detail_id:, separator: ",")
  raise ArgumentError, "Invalid file" unless file.is_a?(HTTP::FormData::File)

  body = post_upload("/api/v3/admin/broadcast/upload_csv", {
    file: file,
    template_detail_id: template_detail_id,
    separator: separator
  })

  body.broadcast_file_id
end