Skip to content

Instantly share code, notes, and snippets.

@Jberlinsky
Created May 16, 2011 14:39
Show Gist options
  • Save Jberlinsky/974544 to your computer and use it in GitHub Desktop.
Save Jberlinsky/974544 to your computer and use it in GitHub Desktop.
def create_interaction(self, client_key, client_secret, subdomain,
48 visitor_email, chat_description, visitor_name, subject='',
49 case_id=None):
50
51 if visitor_name == '':
52 visitor_name = 'Olark Visitor'
53
54 if visitor_email == '':
55 cust_id = self.create_lead(client_key, client_secret, subdomain,
56 visitor_email, visitor_name.replace(",",""))
57
58 url = 'https://%s.assistly.com/api/v1/interactions.json' % subdomain
59
60 data = {}
61 data['interaction_channel'] = 'phone'
62 if visitor_email == '':
63 data['customer_id'] = cust_id
64 else:
65 data['interaction_channel'] = 'email'
66
67 data['customer_email'] = visitor_email
68
69 if subject == '':
70 if visitor_email == '':
71 data['interaction_subject'] = 'Olark chat with %s' % visitor_name
72 else:
73 data['interaction_subject'] = 'Olark chat with %s' % visitor_email
74 else:
75 data['interaction_subject'] = subject
76
77 data['interaction_body'] = chat_description
78
79 if visitor_name != '':
80 visitor_name = visitor_name.replace(",", "")
81 data['customer_name'] = visitor_name
82
83 if case_id is not None:
84 data['case_id'] = case_id
85
86 try:
87 request, response = oauth_request(
88 url=url,
89 key=client_key,
90 secret=client_secret,
91 consumer_key=self.__consumer_key,
92 consumer_secret=self.__consumer_secret,
93 http_method="POST",
94 post_body=urlencode(data))
95 except httplib2.HttpLib2Error, e:
96 request = e
97
98 if request['status'] != '200':
99 raise ValueError(response)
100
101 print "Made request to ", url
102
103 ret_dict = simplejson.loads(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment