README.md in qismo-0.17.10 vs README.md in qismo-0.18.0

- old
+ new

@@ -14,19 +14,18 @@ ```ruby client = Qismo::Client.new(app_id: "QISCUS_APP_ID", secret_key: "QISCUS_SECRET_KEY") params = { - channel: { channel_id: 12345, source: "wa" }, + channel: [{ channel_id: 12345, source: "wa" }], status: "unresolved", serve_status: "served", is_handled_by_bot: true, } -rooms = client.rooms(params) +pp client.list_rooms(params) -puts rooms # [ # #<Qismo::Objects::CustomerRoom # channel_id=126392 # contact_id=21608346 # id=68303333 @@ -74,15 +73,15 @@ **instrumentation** For advanced logging, you can also use laverage ActiveSupport instrumentation. If you are using Rails, you can use ActiveSupport without installing the gem by your self. ```ruby -ActiveSupport::Notifications.subscribe('start_request.http') d |name, start, finish, id, payload| - pp :name => name, :start => start.to_f, :finish => finish.to_f, :id => id, :payload => payload +ActiveSupport::Notifications.subscribe('start_request.http') do |name, start, finish, id, payload| + pp name: name, start: start.to_f, finish: finish.to_f, id: id, payload: payload end -client.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter }client.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter }client.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter } +client.instrumentation = { instrumenter: ActiveSupport::Notifications.instrumenter } ``` You can also customize the instrumentation's namespace by using this configuration ```ruby @@ -122,31 +121,57 @@ ## Handling pagination Some of the Qiscus Omnichannel API will return list of data with pagination. To handle the pagination, you can to that like this example: ```ruby + all_rooms = [] -rooms = client.rooms + +rooms = client.list_rooms all_rooms.append(rooms) -while rooms.has_next_page? - rooms = rooms.next_page +while rooms.next_page.present? + rooms = client.list_rooms(cursor_after: rooms.next_page) all_rooms.append(rooms) end ``` ## Handling error Qismo ruby raise error while getting non successful http code from Qiscus Omnichannel API. To handle it, you follow this example: ```ruby begin - client.rooms -rescue Qismo::HTTPRequestError => e - e.message - e.status_code - e.response_body + client.list_rooms +rescue Qismo::BadRequestError => e + puts e.message + puts e.status_code + puts e.response_body +rescue Qismo::UnauthorizedError => e + puts e.message + puts e.status_code + puts e.response_body +rescue Qismo::PaymentRequiredError => e + puts e.message + puts e.status_code + puts e.response_body +rescue Qismo::ForbiddenError => e + puts e.message + puts e.status_code + puts e.response_body +rescue Qismo::NotFoundError => e + puts e.message + puts e.status_code + puts e.response_body +rescue Qismo::TooManyRequestError => e + puts e.message + puts e.status_code + puts e.response_body +rescue Qismo::InternalServerError => e + puts e.message + puts e.status_code + puts e.response_body end ``` ## Handle incoming webhook request @@ -159,13 +184,14 @@ def handle_agent_allocation_webhook webhook = Qismo::WebhookRequests::OnAgentAllocationNeeded.new(JSON.parse(request.raw_body)) # Do any action you want using payload that has been objectified if webhook.candidate_agent.present? - Qismo.assign_agent( - webhook.room_id, - webhook.candidate_agent.id + client = Qismo::Client.new(app_id: "", secret_key: "") + client.assign_agent( + room_id: webhook.room_id, + agent_id: webhook.candidate_agent.id ) end end def handle_custom_button_webhook @@ -197,11 +223,11 @@ # Assuming that you have installed and setup twitter ruby client # Fetch customer from room participants customer = webhook.payload.room.participants.find { |participant| participant.email.start_with?("twitter_customer_") } if customer.present? - twitter_rest_client.create_direct_message(webhook.payload.rooms, webhook.payload.message.text) + twitter_rest_client.create_direct_message(customer.email, webhook.payload.message.text) end end def handle_bot_webhook webhook = Qismo::WebhookRequests::OnMessageForBotSent.new(JSON.parse(request.raw_body)) @@ -222,11 +248,12 @@ # Parse bot message which will be sent back to customer bot_message = response.query_result.fulfillment_text # Send message to Qismo room - Qismo.send_bot_message( - webhook.payload.room.id, + client = Qismo::Client.new(app_id: "", secret_key: "") + client.send_bot_message( + room_id: webhook.payload.room.id, message: bot_message ) end end ```