Giter Site home page Giter Site logo

gas-freshdesk's Introduction

GasFreshdesk - OO Class for Freshdesk API(v2)

GasFreshdesk is a simple Freshdesk API Class for GAS(Google Apps Script)

Github: https://github.com/huan/gas-freshdesk

Why GasFreshdesk?

I made a number of freshdesk API calls in GAS in order to convert emails from my Gmail account to tickets in my daily life. Most of the emails are business plans with attachments.

I found Freshdesk API very hard to use and debug in GAS, especialy with attachments. Writing more code became more complicated. So I decided to modulize it to GasFreshdesk module.

What does GasFreshdesk look like?

GasFreshdesk is very clean and easy to use.

var MyFreshdesk = new GasFreshdesk('https://mikebo.freshdesk.com', 'Jrg0FQNzX3tzuHbiFjYQ')

var ticket = new MyFreshdesk.Ticket({
  description:'A description'
  , subject: 'A subject'
  , email: '[email protected]'
  , attachments: [ Utilities.newBlob('TEST DATA').setName('test-data.dat') ]
})

ticket.assign(9000658396)
ticket.note({
  body: 'Hi tom, Still Angry'
  , private: true
})
ticket.reply({
  body: 'Hi tom, Still Angry'
  , cc_emails: ['[email protected]']
})
ticket.setPriority(2)
ticket.setStatus(2)

ticket.del()
ticket.restore()

Logger.log('ticket #' + ticket.getId() + ' was set!')

It's very clean and easy to use, huh ;-)

How to enable GasFreshdesk library in GAS?

To use GasFreshdesk in your GAS script editor, just add the follow lines, then you are set.

if ((typeof GasFreshdesk)==='undefined') { // GasFreshdesk Initialization. (only if not initialized yet.)
  eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/zixia/gas-freshdesk/master/src/gas-freshdesk-lib.js').getContentText())
} // Class GasFreshdesk is ready for use now!

API

Gas Freshdesk Library use API v2 to communicate with freshdesk.

The old version use Freshdesk API v1 is Gas Freshdesk Library v0.2.0.

1. Class GasFreshdesk

1.1 GasFreshdesk(url, key): Class constructor for Freshdesk

Return MyFreshdesk for you.

var MyFreshdesk = new GasFreshdesk(
  'YOUR_FRESHDESK_URL_HERE' // i.e. https://mikebo.freshdesk.com
  , 'YOUR_API_KEY_HERE'
)

1.2 MyFreshdesk.listTickets(options)

List or search for tickets. Return a array of instances of Ticket.

  • options.email: email address of requester
  • options.requester_id: requester_id of requester

if options is not provided, then listTickets will uses the new_and_my_open filter.

var tickets = MyFreshdesk.listTickets({ email: '[email protected]' })
var tickets = MyFreshdesk.listTickets({ requester_id: 4312412413 })

2. Class Ticket

2.1 MyFreshdesk.Ticket({...}): Class constructor for Ticket

Create a new ticket for you.

var ticket = new MyFreshdesk.Ticket({
  description:'A totally rad description of a what the problem is'
  , subject:'Something like "Cannot log in"'
  , email: '[email protected]'
  , attachments: [ 
    Utilities.newBlob('TEST DATA').setName('test-data.dat')
    , Utilities.newBlob('TEST2 DATA').setName('test-data2.dat')
  ]
})

2.2 MyFreshdesk.Ticket(id): Class constructor for Ticket

Load a existing ticket for you.

var ticket = new MyFreshdesk.Ticket(1)

2.3 Ticket.del(): Delete ticket

ticket.del()

2.4 Ticket.list(): List tickets

2.5 Ticket.setStatus()

Set ticket to status with parameter.

Has the following shortcut methods:

  1. open()
  2. pend()
  3. resolv()
  4. close()

2.6 Ticket.note()

Note a ticket.

ticket.note({
  body: 'Hi tom, Still Angry'
  , private: true
})

2.7 Ticket.reply()

Reply a ticket.

ticket.reply({
  body: 'Hi tom, Still Angry'
  , cc_emails: ['[email protected]']
})

3. Class Contact

var requesterId = ticket.getRequesterId()
var contact = new MyFreshdesk.Contact(requesterId)

Logger.log(contact.getEmail())

3.1 Contact.list(): List contacts

Search contacts by email.

var Contact = GasFreshdesk.Contact
var contacts = Contact.list({ email: '[email protected]' })
Logger.log(contacts[0].getName())

4. Class Agent

TBW

4.1 Agent.list(options): List agents

Search for agent.

  • options.email email of agent
var Agent = GasFreshdesk.Agent
var agents = Agent.list({ email: '[email protected]' })
Logger.log(agents[0].getId())

Test Suites

There is a test suite that comes with GasFreshdesk, which uses GasTap, a tap testing-framework for GAS.

More sample code could be found in the test files if you like to look into it.

GasFreshdesk test suite: https://github.com/zixia/gas-freshdesk/blob/master/src/gas-freshdesk-tests.js

How to run tests?

You must run tests inside google apps script editor. Open google script editor, copy/paste gas-freshdesk-tests.js into it, then click Run.

There's also an easier way to do it, you could go to my develop environment(read only) to run and clone. Follow this link: https://script.google.com/a/zixia.net/macros/d/Mta4oea1VMIugfSGRo4QrAnKRT9d30hqB/edit?uiv=2&mid=ACjPJvGt4gnXjJwXnToB0jIMEbSvqKUF6vH-uq-m59SqnjXqTQ03NDn_khlNE6ha_mPnrOAYEnyFk80nHYmt_hppO3AgDkO_vVLrYJXzcPPagwRromd0znfLreNFAu4p0rYTC-Jlo-sAKOM, then click gas-freshdesk-test.gs in file browser on the left.

Support

The GasFreshdesk source code repository is hosted on GitHub. There you can file bugs on the issue tracker or submit tested pull requests for review. ( https://github.com/zixia/gas-freshdesk/issues )

For real-world examples from open-source projects using GasL, see Projects Using TasL on the wiki. ( https://github.com/zixia/gas-freshdesk/wiki )

HISTORY

  • Switch to Freshdesk API v2
  • Change library name fromFreshdesk to GasFreshdesk
  • Added new method: Ticket.reply()

To use the v0.3.0 gas-freshdesk library, put the following snip in your gas code.

if ((typeof Freshdesk)==='undefined') { // GasFreshdesk Initialization. (only if not initialized yet.)
  eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/zixia/gas-freshdesk/v0.3.0/src/gas-freshdesk-lib.js').getContentText())
} // Class GasFreshdesk is ready for use now!

To use the v0.2.0 gas-freshdesk library with freshdesk api v1, put the following snip in your gas code.

if ((typeof Freshdesk)==='undefined') { // GasFreshdesk Initialization. (only if not initialized yet.)
  eval(UrlFetchApp.fetch('https://raw.githubusercontent.com/zixia/gas-freshdesk/v0.2.0/src/gas-freshdesk-lib.js').getContentText())
} // Class GasFreshdesk is ready for use now!

v0.1.0(December 16, 2015)

  • Initial public release.

AUTHOR

Huan LI (李卓桓) <[email protected]>

profile for zixia on Stack Exchange, a network of free, community-driven Q&A sites

COPYRIGHT & LICENSE

  • Code & Docs © 2015-now Huan LI <[email protected]>
  • Code released under MIT-style license; see LICENSE for details.
  • Docs released under Creative Commons

gas-freshdesk's People

Contributors

huan avatar kukulor avatar wiktor-jurek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gas-freshdesk's Issues

v2 api notes "include=conversations" update

Vasu to me
Hi,

Really sorry for the trouble caused.

We have modified the code recently and we are yet to update the documentation in our site. Please try the below code and check if it works?

curl -v -u Jrg0FQNzX3tzuHbiFjYQ:X -H "Content-Type: application/json" -X GET 'https://mikebo.freshdesk.com/api/v2/tickets/1?include=conversations'

Check your ticket status - https://support.freshdesk.com/helpdesk/tickets/518460

Regards,
Vasu

On Sat, 12 Mar at 3:06 PM , Zhuohuan LI [email protected] wrote:
not works either.

curl -v -u Jrg0FQNzX3tzuHbiFjYQ:X -H "Content-Type: application/json" -X GET 'https://mikebo.freshdesk.com/api/v2/tickets/1?include=notes'

you can try by yourself, the result is:

{"description":"Validation failed","errors":[{"field":"include","message":"Should be a value in the list 'conversations'","code":"invalid_value"}]}

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Port GasFreshdesk to NodeJS

GasFreshdesk is write to modulize freshdesk api in google apps scripts, so It can't run by nodejs, also it is not packed to NPM yet.

However, I believe port to nodejs is quite easy, because code is clean and only need changes a few class from gas to nodejs. (i.e. UrlFetchApp, Utilities).

Also I like async library. It's better to keep GasFreshdesk to be async in nodejs.

Contribution is very welcome, because I mainly use GasFreshdesk inside gas.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

List tickets to sheet

Hi Huan, it seems very useful your library. Thanks for this effort. I would like to write to sheet a list of tickets returned by MyFreshdesk.listTickets() function. Do you have a sample to do this?

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.