1.0.0 • Published 4 years ago

onechat v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

การลง library

npm install onechat

ในไฟล์ main.js

import Vue from 'vue'
import Onechat from 'Onechat'
Vue.use(Onechat)

เริ่มต้นการใช้งานด้วย

this.$Onechat.authorization({username: ‘’, password: ‘’})

หรือ

this.$Onechat.authorization({accesstoken: ‘’})

จากนั้นจึงเริ่มใช้งานfunctionอื่นๆได้

RoomSocket ()

สำหรับดึงข้อมูลroom socket ของตัวเอง สำหรับการเชื่อมต่อ socket ดูได้ที่ด้านล่าง

this.$Onechat.RoomSocket()

get_myinformation ()

สำหรับดึงข้อมูลของตัวเอง

this.$Onechat.get_myinformation().then((response) => {
    //นำresponseไปใช้งานต่อ
})

get_user_information (String tokenuser)

สำหรับดึงข้อมูลของคนอื่น

this.$Onechat.get_user_information(tokenuser).then((response) => {
    //นำresponseไปใช้งานต่อ
})

search_user_infomation (String key)

สำหรับค้นหาข้อมูลเพื่อน สำหรับใช้ในการเพิ่มเพื่อนในลำดับถัดไป โดย key ที่ใช้ค้นหาเป็น email, username , phone, bot_id และ nickname ของบอท

this.$Onechat.search_user_infomation(key).then((response) => {
    //นำresponseไปใช้งานต่อ
})

add_friend (String tokenuserfriend)

สำหรับเพิ่มเพื่อน

this.$Onechat.add_friend(tokenuserfriend).then((response) => {
    //นำresponseไปใช้งานต่อ
})

accept_friend (String tokenuserfriend)

สำหรับตอบรับคำขอเป็นเพื่อน

this.$Onechat.accept_friend(tokenuserfriend).then((response) => {
    //นำresponseไปใช้งานต่อ
})

create_group (String name, String[] listmember)

สำหรับสร้างกลุ่มแชท

this.$Onechat.create_group(name, listmember).then((response) => {
    //นำresponseไปใช้งานต่อ
})

accept_group (String group_id)

สำหรับตอบรับเข้ากลุ่มแชท

this.$Onechat.accept_group(group_id).then((response) => {
    //นำresponseไปใช้งานต่อ
})

leave_group (String group_id)

สำหรับออกจากกลุ่มแชท

this.$Onechat.leave_group(group_id).then((response) => {
    //นำresponseไปใช้งานต่อ
})

kick_member_group (String group_id, String listmemeber[])

สำหรับลบคนออกจากกลุ่มแชท

this.$Onechat.kick_member_group(group_id, listmemeber).then((response) => {
    //นำresponseไปใช้งานต่อ
})

get_list_pendingfriend ()

สำหรับดึงข้อมูลuserที่ส่งคำขอเป็นเพื่อนไป แล้วรอการตอบรับ

this.$Onechat.get_list_pendingfriend().then((response) => {
    //นำresponseไปใช้งานต่อ
})

get_list_requestfriend ()

สำหรับดึงข้อมูลuserที่ส่งคำขอเป็นเพื่อนเข้ามา

this.$Onechat.get_list_requestfriend().then((response) => {
    //นำresponseไปใช้งานต่อ
})

get_list_pendinggroup ()

สำหรับดึงข้อมูลกลุ่มที่ส่งคำชวนเข้ากลุ่ม

this.$Onechat.get_list_pendinggroup().then((response) => {
    //นำresponseไปใช้งานต่อ
})

get_list_friend ()

สำหรับดึงข้อมูลเพื่อนที่มีทั้งหมด

this.$Onechat.get_list_friend().then((response) => {
    //นำresponseไปใช้งานต่อ
})

get_list_group ()

สำหรับดึงข้อมูลกลุ่มที่มีทั้งหมด

this.$Onechat.get_list_group().then((response) => {
    //นำresponseไปใช้งานต่อ
})

get_list_chat ()

สำหรับดึงข้อมูลแชทที่มีทั้งหมด

this.$Onechat.get_list_chat().then((response) => {
    //นำresponseไปใช้งานต่อ
})

get_message (String tokenmessage)

สำหรับดึงข้อมูลข้อความ

this.$Onechat.get_message(tokenmessage).then((response) => {
    //นำresponseไปใช้งานต่อ
})

get_list_message (String tokenroom, String datetime)

สำหรับดึงข้อมูลข้อความแบบเป็น list โดยฟังก์ชันจะดึงข้อความ 20 ข้อความ ก่อนเวลาที่กำหนดมาในตัวแปร

this.$Onechat.get_list_message(tokenroom, datetime).then((response) => {
    //นำresponseไปใช้งานต่อ
})

push_text (String tokenroom, String message)

สำหรับส่งข้อความประเภท text

this.$Onechat.push_text(tokenroom,message).then((response) => {
    //นำresponseไปใช้งานต่อ
})

push_location (String tokenroom, String address, double lat, double long)

สำหรับส่งข้อความประเภท location โดย address เป็นชื่อหรือรายละเอียดของสถานที่

this.$Onechat.push_location(tokenroom,address,lat,long).then((response) => {
    //นำresponseไปใช้งานต่อ
})

push_file (String tokenroom, File file)

สำหรับส่งข้อความประเภทไฟล์

this.$Onechat.push_file(tokenroom,file).then((response) => {
    //นำresponseไปใช้งานต่อ
})

push_sticker (String tokenroom, String sticker_id)

สำหรับส่งข้อความประเภทสติกเกอร์

this.$Onechat.push_sticker(tokenroom,sticker_id).then((response) => {
    //นำresponseไปใช้งานต่อ
})

get_list_sticker ()

สำหรับดึงข้อมูลสติกเกอร์ทั้งหมด

this.$Onechat.get_list_sticker().then((response) => {
    //นำresponseไปใช้งานต่อ
})

get_quickReply (String tokenroom)

สำหรับดึงข้อมูลquickReply ในห้องแชทนั้นๆ

this.$Onechat.get_quickReply(tokenroom).then((response) => {
    //นำresponseไปใช้งานต่อ
})

answer_quickReply (String tokenroom, Dictionary answer, String quickReply_id)

สำหรับการกดเลือกquickReply ในห้องแชทนั้นๆ โดยanswer คือ choice ของ คำตอบที่กดเลือก และ quickReply_id คือ _id ของ quickReply

this.$Onechat.answer_quickReply(tokenroom, answer, quickReply_id).then((response) => {
    //นำresponseไปใช้งานต่อ
})

เริ่มต้นการใช้งาน Socket ด้วย

this.$OnechatSocket.on('connect', function () {})

Emit

join

สำหรับสร้างroom เพื่อรอรับ event อื่นๆ

this.$OnechatSocket.emit('join', {room: this.roomsocket, type: 'web'})

โดย this.roomsocket = this.$Onechat.RoomSocket()

On Event

message

สำหรับรอรับการแจ้งเตือนเมื่อมีข้อความใหม่เข้ามา

this.$OnechatSocket.on('message', function (data) { 
    //นำdata ไปใช้งานต่อ
    //"data": {
    //   "tokenmessage": "นำ tokenmessage ไปดึงข้อมูลต่อ",
    //   "tokenroom": "ห้องแชทที่ส่งข้อความ",
    //   "tokenuser": "คนส่งข้อความ"
    //}
})

event_friend

สำหรับรอรับการแจ้งเตือนเมื่อมีการเพิ่มเพื่อน

this.$OnechatSocket.on('event_friend', function (data) { 
    //นำdata ไปใช้งานต่อ
    //"data": {
    //   "tokenuser": "คนที่ส่งคำขอเป็นเพื่อน",
    //   "tokenfriend": "คนถูกเพิ่มเพื่อน"
    //}
})

event_accept_friend

สำหรับรอรับการแจ้งเตือนเมื่อมีการกดรับเพิ่มเพื่อน

this.$OnechatSocket.on('event_accept_friend', function (data) { 
    //นำdata ไปใช้งานต่อ
    //"data": {
    //   "tokenuser": "คนกดยอมรับเพื่อน",
    //   "tokenfriend": "คนที่ส่งคำขอเป็นเพื่อน",
    //   "tokenroom": "ห้องแชทส่งข้อความ"
    //   "timestamp": "เวลา ณ ที่รับเพื่อน"
    //}
})

event_create_group

สำหรับรอรับการแจ้งเตือนเมื่อมีการสร้างกลุ่ม

this.$OnechatSocket.on('event_create_group', function (data) { 
    //นำdata ไปใช้งานต่อ
    //"data": {
    //   "listmember": ["list tokenuser ของคนที่ถูกชวนทั้งหมด"],
    //   "groupid": "ไอดีกลุ่ม",
    //   "fromtokenuser": "tokenuser ของคนที่สร้างกลุ่ม"
    //}
})

event_invite_group

สำหรับรอรับการแจ้งเตือนเมื่อมีการชวนคนเข้ากลุ่มเพิ่ม

this.$OnechatSocket.on('event_invite_group', function (data) { 
    //นำdata ไปใช้งานต่อ
    //"data": {        
    //    "tokenuser": "tokenuser ของ คนชวนเข้ากลุ่ม",
    //    "tokenroom": "ห้องส่งข้อความ", 
    //    "groupid": "ไอดีกลุ่ม",
    //    "memberingroup": [ "list tokenuser ของ คนที่อยู่ในกลุ่มอยู่แล้ว"] ,
    //    "invited": [ "list tokenuser ของ คนที่ถูกชวนเข้ากลุ่ม" ],
    //    "message": "คำแสดงเมื่อชวนคนเข้ากลุ่ม" 
    //}
})

event_active_group

สำหรับรอรับการแจ้งเตือนเมื่อมีการชวนคนกดรับเข้ากลุ่ม

this.$OnechatSocket.on('event_active_group', function (data) { 
    //นำdata ไปใช้งานต่อ
    //"data": {        
    //    "tokenuser": "tokenuser ของ คนตอบรับเข้ากลุ่ม",
    //    "timestamp": "เวลา ณ ที่เข้ากลุ่ม", 
    //    "groupid": "ไอดีกลุ่ม" 
    //}
})

event_leave_group

สำหรับรอรับการแจ้งเตือนเมื่อมีคนกดออกจากกลุ่ม

this.$OnechatSocket.on('event_leave_group', function (data) { 
    //นำdata ไปใช้งานต่อ
    //"data": {        
    //    "tokenuser": "ผู้ที่เป็นคนเชิญคนออก",
    //    "tokenroom": "ห้องแชทส่งข้อความ",
    //    "message": "คำแสดงเมื่อมีคนออกกลุ่ม",
    //    "listmember": ["list ของ tokenuser คนที่อยู่ในกลุ่ม “],
    //    "listkick": ["list ของ tokenuser คนที่โดนลบ"]
    //}
})